TLE '16 Contest 5 P3 - Flight Exam

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Fax McClad cruising in Cronerian skies on his Kyuwing.

Fax McClad, Croneria's most well respected bounty hunter, needs to renew his flight license. In order to do so, he will have to take a flight examination.

For the examination, Fax is required to fly straight, but he can change his altitude. In front of him, there are N checkpoints: the ith one is located di kilometers from his starting point and has an altitude of ai meters.

Fax can increase his altitude at a rate of up to I meters per kilometer traveled and can decrease his altitude at a rate of up to D meters per kilometer traveled. Fax's initial altitude is 0 meters and he cannot go below this altitude.

Fax is able to do a special technique called the somersault. When he performs this technique, he will rise S meters before going back down to his original altitude in a loop fashion. In doing so, he can go through a checkpoint that is exactly S meters above him from his original altitude, if one exists.

Fax's exam ends when there are no more checkpoints in front of him. His score is determined by the number of checkpoints he passes. What is the maximum number of checkpoints that Fax can pass through?

Constraints

1N1000

0I,D,S,ai109

1di109

For 40% of the points, N10.

Note to Python users: It is recommended to submit in PyPy.

Input Specification

The first line of input will contain four space-separated integers: N, I, D, and S.

N lines of input follow. The ith line will contain two space-separated integers: di and ai, specifying the distance and the altitude of the ith checkpoint. It is guaranteed that all (di,ai) are pairwise distinct.

Output Specification

Output a single integer, the maximum number of checkpoints that Fax can pass through.

Sample Input

Copy
6 400 200 300
2 600
3 1000
3 1200
3 1300
5 700
6 200

Sample Output

Copy
4

Diagram for Sample

The black points signify the checkpoints, and the red line is the optimal path that Fax McClad can take.


Comments


  • 0
    jimgao  commented on Jan. 20, 2017, 3:08 p.m.

    Can he perform the somersault when he is not currently at a checkpoint?


    • 0
      r3mark  commented on Jan. 20, 2017, 3:16 p.m.

      Yes.