题目描述
Problem Description
At JOI High School, a vote was held on a certain issue to decide whether to "approve" or "oppose". $ N $ students voted in order, and each student could know the votes of other students who had voted before them.
The $ i $th ($1 \leq i \leq N$) student voted "approve" if the following condition was met, otherwise they voted "oppose":
- Among the $ X_i $ students who voted immediately before them, i.e., the students who voted in positions $ i-1, i-2, ..., i-X_i $, at least $ Y_i $ students voted "approve".
However, if $ Y_i = 0 $, the student voted "approve" regardless of other students' votes, and if $ Y_i = X_i + 1 $, the student voted "oppose" regardless of other students' votes.
Given the information about each student's vote, create a program to find the number of students who voted "approve".
Input Format
The input is given from the standard input in the following format:
$ N $ $ X_1 $ $ Y_1 $ $ X_2 $ $ Y_2 $ $\vdots$ $ X_N $ $ Y_N $
Output Format
Output the number of students who voted "approve" in one line to the standard output.
Sample Input and Output
Sample Input #1
4
0 1
1 0
1 1
3 3
Sample Output #1
2
Sample Input #2
5
0 0
1 1
2 3
3 1
4 3
Sample Output #2
4
Sample Input #3
10
0 0
1 2
1 1
1 0
3 1
2 3
1 1
5 3
8 4
7 2
Sample Output #3
4
Notes/Hints
Constraints
- $1 \leq N \leq 500,000$.
- $0 \leq X_i \leq i-1$ ($1 \leq i \leq N$).
- $0 \leq Y_i \leq X_i + 1$ ($1 \leq i \leq N$).
- All input values are integers.
Subtasks
- ($ 28 $ points) $N \leq 3,000$.
- ($ 32 $ points) $ X_i = i-1 $ ($1 \leq i \leq N$).
- ($ 40 $ points) No additional constraints.
Grading Notes
All submissions are graded on the judge system.
A submitted source code is considered correct for a subtask if it returns the correct result for all test input data corresponding to that subtask.
The score for each submission is the sum of the points for the subtasks that the submitted source code is considered correct for.
The score for this task is the maximum score of all submissions for this task.
The current score can be checked from the "My Score Status" tab in the "Submission Results".
Sample Explanation 1
The vote was conducted sequentially by 4 students as follows:
1. The 1st student voted "oppose" because $ Y_1 = X_1 + 1 $.
2. The 2nd student voted "approve" because $ Y_2 = 0 $.
3. The 3rd student voted "approve" because among the $ X_3 (=1) $ students who voted immediately before, 1 student voted "approve", which is at least $ Y_3 (=1) $.
4. The 4th student voted "oppose" because among the $ X_4 (=3) $ students who voted immediately before, 2 students voted "approve", which is not at least $ Y_4 (=3) $.
Thus, 2 students voted "approve". Therefore, output 2. This input example satisfies the constraints of subtasks 1 and 3.
Sample Explanation 2
This input example satisfies the constraints of all subtasks.
Sample Explanation 3
This input example satisfies the constraints of subtasks 1 and 3.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分