Logo
(追記) (追記ここまで)

31559번 - Cannonball 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB65320617533.144%

문제

Bessie has mastered the art of turning into a cannonball and bouncing along a number line of length $N$ $(1 \leq N \leq 10^5)$ with locations numbered 1,2,ドル\dots,N$ from left to right. She starts at some integer location $S$ $(1 \leq S \leq N)$ bouncing to the right with a starting power of 1ドル$. If Bessie has power $k,ドル her next bounce will be at a distance $k$ forward from her current location.

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.

입력

The first line of the input contains $N$ and $S,ドル where $N$ is the length of the number line and $S$ is Bessie's starting location.

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 one number representing the number of targets that will be broken.

제한

예제 입력 1

5 2
0 1
1 1
1 2
0 1
1 1

예제 출력 1

1

Bessie starts at coordinate 2ドル,ドル which is a target of value 1ドル,ドル so she immediately breaks it. She then bounces to coordinate 3ドル,ドル which is a target of value 2ドル,ドル so she can't break it. She continues to coordinate 4ドル,ドル which switches her direction and increases her power by 1ドル$ to 2ドル$. She bounces back to coordinate 2ドル,ドル which is an already broken target, so she continues. At this point, she bounces to coordinate 0ドル,ドル so she stops. She breaks exactly one target at located at 2ドル$.

예제 입력 2

6 4
0 3
1 1
1 2
1 1
0 1
1 1

예제 출력 2

3

The path Bessie takes is 4ドル\to 5\to 3\to 1\to 6,ドル where the next bounce would take her out of the number line (11ドル$). She breaks targets 4,ドル 3, 6$ in that order.

힌트

출처

Olympiad > USA Computing Olympiad > 2023-2024 Season > USACO 2024 January Contest > Bronze 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /