Cannonball
Time limit2sMemory limit1024 MB
Given a number line of targets and jump pads, count how many targets Bessie breaks while bouncing from her starting cell.
- Level
Medium6 of 10
- Topics
- Simulation, Array
- Solved
- No attempts yet
Problem
Bessie has mastered the art of turning into a cannonball and bouncing along a number line of length () with locations numbered from left to right. She starts at integer location () bouncing to the right with a starting power of 1. If Bessie has power , her next bounce lands at a distance forward from her current location.
Every integer location from 1 to is either a target or a jump pad. Each target and jump pad has an integer value from 0 to inclusive. A jump pad with value increases Bessie's power by and reverses her direction. A target with value breaks if Bessie lands on it with a power of at least . Landing on a target does not change her power or direction. A broken target stays broken, and Bessie can still bounce on it without changing power or direction.
If Bessie bounces forever or until she leaves the number line, how many targets will she break?
If Bessie starts on a target she can break, she breaks it immediately. Likewise, if she starts on a jump pad, the pad's effect applies before her first jump.
Input
The first line contains and , where is the length of the number line and is Bessie's starting location.
The next lines describe each location. The -th line contains integers and , where if location is a jump pad and if location is a target, and is the value of location .
Output
Output one number, the number of targets that will be broken.