/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 466 点
問題文
数直線上でスタンプラリーが開催されています。
数直線上には 1 から N までの番号が付けられた N 箇所のチェックポイントがあります。チェックポイント i は座標 X_i に設置されており、スタンプの獲得期限は時刻 T_i です。
高橋君は時刻 0 に座標 0 を出発し、数直線上を最大で速さ 1 で移動することができます(移動する向きの反転や停止はいつでも自由に行えます)。
高橋君は、時刻 T_i 以前に座標 X_i に到達することで、チェックポイント i のスタンプを 1 つ獲得できます(その座標を通過するだけでも獲得できます)。ただし、各チェックポイントのスタンプは 1 つまでしか獲得できず、スタンプの獲得にかかる時間は無視できます。
高橋君が最適に行動したとき、獲得できるスタンプの個数の最大値を求めてください。
制約
- 1 \leq N \leq 100
- -10^9 \leq X_i \leq 10^9 (1 \leq i \leq N)
- X_i \neq 0 (1 \leq i \leq N)
- X_i \neq X_j (1 \leq i < j \leq N)
- 0 \leq T_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数
入力
入力は以下の形式で与えられる。
N X_1 T_1 X_2 T_2 \vdots X_N T_N
出力
高橋君が獲得できるスタンプの個数の最大値を 1 行で出力してください。
入力例 1
3 1 3 -2 5 4 4
出力例 1
2
入力例 2
3 5 2 -10 8 100 50
出力例 2
0
入力例 3
12 -35 80 -20 30 -12 15 -5 7 -2 2 3 4 8 10 15 25 25 50 40 90 -60 120 70 110
出力例 3
6
入力例 4
30 -892301492 900000000 -820194821 850000000 -749102840 800000000 -681920491 750000000 -610294819 700000000 -549102948 600000000 -481920394 550000000 -419204918 500000000 -359102948 450000000 -281920491 350000000 -210294819 300000000 -149102948 200000000 -81920394 100000000 -29102948 50000000 -10294819 20000000 15920394 25000000 34910294 40000000 78192039 90000000 139102948 180000000 201920491 250000000 270294819 320000000 349102948 400000000 410294819 480000000 479102948 550000000 541920491 620000000 610294819 700000000 679102948 780000000 741920491 850000000 810294819 920000000 889102948 990000000
出力例 4
15
入力例 5
1 -1000000000 1000000000
出力例 5
1
Score : 466 pts
Problem Statement
A stamp rally is being held on a number line.
There are N checkpoints on the number line, numbered 1 through N. Checkpoint i is located at coordinate X_i, and the deadline to collect its stamp is time T_i.
Takahashi starts at coordinate 0 at time 0, and can move along the number line at a speed of at most 1 (he can change direction or stop at any time).
By reaching coordinate X_i at or before time T_i, Takahashi can collect the stamp of checkpoint i (merely passing through that coordinate is sufficient to collect it). However, he can collect at most one stamp from each checkpoint, and the time required to collect a stamp is negligible.
Find the maximum number of stamps Takahashi can collect if he acts optimally.
Constraints
- 1 \leq N \leq 100
- -10^9 \leq X_i \leq 10^9 (1 \leq i \leq N)
- X_i \neq 0 (1 \leq i \leq N)
- X_i \neq X_j (1 \leq i < j \leq N)
- 0 \leq T_i \leq 10^9 (1 \leq i \leq N)
- All input values are integers.
Input
The input is given in the following format:
N X_1 T_1 X_2 T_2 \vdots X_N T_N
Output
Print the maximum number of stamps Takahashi can collect in a single line.
Sample Input 1
3 1 3 -2 5 4 4
Sample Output 1
2
Sample Input 2
3 5 2 -10 8 100 50
Sample Output 2
0
Sample Input 3
12 -35 80 -20 30 -12 15 -5 7 -2 2 3 4 8 10 15 25 25 50 40 90 -60 120 70 110
Sample Output 3
6
Sample Input 4
30 -892301492 900000000 -820194821 850000000 -749102840 800000000 -681920491 750000000 -610294819 700000000 -549102948 600000000 -481920394 550000000 -419204918 500000000 -359102948 450000000 -281920491 350000000 -210294819 300000000 -149102948 200000000 -81920394 100000000 -29102948 50000000 -10294819 20000000 15920394 25000000 34910294 40000000 78192039 90000000 139102948 180000000 201920491 250000000 270294819 320000000 349102948 400000000 410294819 480000000 479102948 550000000 541920491 620000000 610294819 700000000 679102948 780000000 741920491 850000000 810294819 920000000 889102948 990000000
Sample Output 4
15
Sample Input 5
1 -1000000000 1000000000
Sample Output 5
1