B - ARC Division 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MiB



配点 : 200

問題文

AtCoder では、ARC が 2 つの division に分けられています。

  • ARC Div. 1 では、コンテスト開始時のレーティングが 1600 以上 2799 以下の参加者がレーティング更新の対象です。
  • ARC Div. 2 では、コンテスト開始時のレーティングが 1200 以上 2399 以下の参加者がレーティング更新の対象です。

高橋くんは、これから N 回の ARC に参加することにしました。

はじめ、高橋くんのレーティングは R です。

i 回目 (1\leq i\leq N) の ARC は Div. D _ i で、高橋くんが取った成績は整数 A _ i で表されます。

i 回目の ARC において高橋くんがレーティング更新の対象ならば、コンテスト開始時の高橋くんのレーティングを T として、更新後の高橋くんのレーティングは T+A _ i になります。 高橋くんがレーティング更新の対象でなければ、高橋くんのレーティングは変化しません。

ARC でのレーティングの更新はコンテストが終了したあと直ちに行われ、次のコンテストのレーティング更新の対象であるかは更新後のレーティングをもとに判定されます。

N 回の ARC を終えたとき、高橋くんのレーティングがいくつになっているか求めてください。

ただし、高橋くんはこの N 回の ARC 以外のコンテストには参加せず、ARC 以外でレーティングが変動することはありません。

制約

  • 1\leq N\leq 100
  • 0\leq R\leq 4229
  • 1\leq D _ i\leq 2\ (1\leq i\leq N)
  • -1000\leq A _ i\leq 1000\ (1\leq i\leq N)
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N R
D _ 1 A _ 1
D _ 2 A _ 2
\vdots
D _ N A _ N

出力

N 回の ARC を終えた後の、高橋くんのレーティングを出力せよ。


入力例 1

4 1255
2 900
1 521
2 600
1 52

出力例 1

2728

はじめ、高橋くんのレーティングは 1255 です。

それぞれのコンテストで、高橋くんのレーティングは次のように変化します。

  • 1 回目の ARC は Div. 2 です。高橋くんはレーティング更新の対象なので、高橋くんのレーティングは 1255+900=2155 になります。
  • 2 回目の ARC は Div. 1 です。高橋くんはレーティング更新の対象なので、高橋くんのレーティングは 2155+521=2676 になります。
  • 3 回目の ARC は Div. 2 です。高橋くんはレーティング更新の対象ではないので、高橋くんのレーティングは変化しません。
  • 4 回目の ARC は Div. 1 です。高橋くんはレーティング更新の対象なので、高橋くんのレーティングは 2676+52=2728 になります。

4 回の ARC を終えた後、高橋くんのレーティングは 2728 となっているので、2728 を出力してください。


入力例 2

2 3031
1 1000
2 -1000

出力例 2

3031

高橋くんはレッドコーダーなので、ARC でどのような成績を取ってもレーティングは変動しません。


入力例 3

15 2352
2 -889
2 420
2 -275
1 957
1 -411
1 -363
1 151
2 -193
2 289
2 -770
2 109
1 345
2 551
1 -702
1 355

出力例 3

1226

Score : 200 points

Problem Statement

AtCoder Regular Contest (ARC) is divided into two divisions.

  • In ARC Div. 1, participants whose rating at the start of the contest is between 1600 and 2799, inclusive, are subject to rating updates.
  • In ARC Div. 2, participants whose rating at the start of the contest is between 1200 and 2399, inclusive, are subject to rating updates.

Takahashi decided to participate in N ARCs.

Initially, his rating is R.

The i-th (1\leq i\leq N) ARC is Div. D _ i, and his performance in that contest is represented by an integer A _ i.

If he is subject to a rating update in the i-th ARC, let T be his rating at the start of that contest. Then, after the contest, his rating becomes T+A _ i.

If his is not subject to a rating update, his rating does not change.

Rating updates for ARCs are performed immediately after the contest ends, and whether he is subject to rating updates in the next contest is determined based on his rating after the update.

Find his rating after finishing the N ARCs.

He does not participate in any contests other than these N ARCs, and his rating does not change in other ways.

Constraints

  • 1\leq N\leq 100
  • 0\leq R\leq 4229
  • 1\leq D _ i\leq 2\ (1\leq i\leq N)
  • -1000\leq A _ i\leq 1000\ (1\leq i\leq N)
  • All input values are integers.

Input

The input is given in the following format from Standard Input:

N R
D _ 1 A _ 1
D _ 2 A _ 2
\vdots
D _ N A _ N

Output

Print Takahashi's rating after finishing the N ARCs.


Sample Input 1

4 1255
2 900
1 521
2 600
1 52

Sample Output 1

2728

Initially, Takahashi's rating is 1255.

For each contest, Takahashi's rating changes as follows:

  • The 1st ARC is Div. 2. He is subject to rating updates, so his rating becomes 1255+900=2155.
  • The 2nd ARC is Div. 1. He is subject to rating updates, so his rating becomes 2155+521=2676.
  • The 3rd ARC is Div. 2. He is not subject to rating updates, so his rating does not change.
  • The 4th ARC is Div. 1. He is subject to rating updates, so his rating becomes 2676+52=2728.

After the four ARCs, his rating is 2728, so print 2728.


Sample Input 2

2 3031
1 1000
2 -1000

Sample Output 2

3031

He is a Red coder, so his rating does not change upon his performance in ARC.


Sample Input 3

15 2352
2 -889
2 420
2 -275
1 957
1 -411
1 -363
1 151
2 -193
2 289
2 -770
2 109
1 345
2 551
1 -702
1 355

Sample Output 3

1226