#CCBCHHAI0000034. Số phiên trước lệnh dừng (Valid Sessions Before Stop)
Số phiên trước lệnh dừng (Valid Sessions Before Stop)
Valid Sessions Before Stop
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
A stream consists of pairs (k, x). For k=1, count the attempt only if . Code k=0 terminates the stream and is not counted. The final pair is 0 0. Both endpoint values 0 and 10 are valid.
Input
A sequence of integer pairs k x, k in {0,1}. The last pair is 0 0; all previous codes are 1. An operand of code 1 may be outside the accepted range.
Output
Print the number of code-1 pairs whose operand belongs to the closed interval [0,10].
Subtasks
- Subtask 1 (20%): At most 5 pairs including stop; .
- Subtask 2 (30%): At most 100 pairs including stop; .
- Subtask 3 (50%): At most 10000 pairs including stop; .
Examples
Example 1
Input
1 5
1 11
1 0
0 0
Output
2
Explanation
5 and 0 belong to [0,10]; 11 does not. The terminating pair is excluded.
Example 2
Input
1 10
1 -1
0 0
Output
1
Explanation
10 is valid at the upper endpoint, -1 is not, so the answer is 1.