10438: USACO 2024 January Contest, Bronze Problem 2. Cannonball
Description
Every integer location from $1$ to $N$ is either a target or a jump pad. Each target and jump pad has an integer value in the range $0$ to $N$ inclusive. A jump pad with a value of $v$ increases Bessie's power by $v$ and reverses her direction. A target with a value of $v$ will be broken if landed on with a power of at least $v$. Landing on a target does not change Bessie's power or direction. A target that is broken will remain broken and Bessie can still bounce on it, also without changing power or direction.
If Bessie bounces for an infinite amount of time or until she leaves the number line, how many targets will she break?
If Bessie starts on a target that she can break, she will immediately do so. Similarly, if Bessie starts on a jump pad, the pad's effects will be applied before her first jump.
Input
The next $N$ lines describe each of the locations. The $i$th of these lines contains integers $q_i$ and $v_i$, where $q_i = 0$ if location $i$ is a jump pad and $q_i = 1$ if location $i$ is a target, and where $v_i$ is the value of location $i$.
Output
Constraints
- Inputs 3-5: $N \le 100$
- Inputs 6-10: $N \le 1000$
- Inputs 11-20: No additional constraints.
Sample 1 Input
5 2
0 1
1 1
1 2
0 1
1 1
Sample 1 Output
1
Sample 2 Input
6 4
0 3
1 1
1 2
1 1
0 1
1 1
Sample 2 Output
3