Exploration
Time limit1sMemory limit128 MB
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 (). There are () landmarks located at positions (). Bessie wants to visit as many landmarks as possible before sundown, which arrives in () 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 .)
Input
- Line 1: Two space-separated integers, and .
- Lines 2 to : Line contains a single integer, the position of the -th landmark.
Output
- A single line containing the maximum number of landmarks Bessie can visit.