This page is still under construction.

Parts of this page are still being built. What you see may change.

Exploration

Time limit1sMemory limit128 MB

Summary
Landmarks on a number line are visited in order of increasing distance from the origin; find the maximum number she can reach within T minutes.
Level

Medium7 of 10

Topics
Greedy, Sorting, Math, Brute force
Solved
No attempts yet

Problem

Bessie is traveling along a road dotted with interesting landmarks. The road is laid out like a number line, and Bessie starts at the origin (x=0x = 0). There are NN (1≤N≤50,0001 \le N \le 50{,}000) landmarks located at positions x1,x2,…,xNx_1, x_2, \ldots, x_N (−100,000≤xi≤100,000-100{,}000 \le x_i \le 100{,}000). Bessie wants to visit as many landmarks as possible before sundown, which arrives in TT (1≤T≤1,000,000,0001 \le T \le 1{,}000{,}000{,}000) minutes. She travels one unit of distance per minute.

Bessie visits the landmarks in a fixed order. Because landmarks closer to the origin matter more, she always heads next for the unvisited landmark closest to the origin. No two landmarks are the same distance from the origin, so the next landmark she heads for is always uniquely determined.

Determine the maximum number of landmarks Bessie can visit before the day ends. (A landmark counts as visited only if she arrives at it no later than minute TT.)

Input

  • Line 1: Two space-separated integers, TT and NN.
  • Lines 2 to N+1N+1: Line i+1i+1 contains a single integer, the position xix_i of the ii-th landmark.

Output

  • A single line containing the maximum number of landmarks Bessie can visit.

Examples1

  1. Example 1

    Input
    25 5
    10
    -3
    8
    -7
    1
    
    Expected output
    4