A - Serval vs Monster

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

サーバルはモンスターと戦っています。

モンスターの体力は H です。

サーバルが攻撃を 1 回行うとモンスターの体力を A 減らすことができます。 攻撃以外の方法でモンスターの体力を減らすことはできません。

モンスターの体力を 0 以下にすればサーバルの勝ちです。

サーバルがモンスターに勝つために必要な攻撃の回数を求めてください。

制約

  • 1 \leq H \leq 10^4
  • 1 \leq A \leq 10^4
  • 入力中のすべての値は整数である。

入力

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

H A

出力

サーバルがモンスターに勝つために必要な攻撃の回数を出力せよ。


入力例 1

10 4

出力例 1

3
  • 1 回目の攻撃の後のモンスターの体力は 6 です。
  • 2 回目の攻撃の後のモンスターの体力は 2 です。
  • 3 回目の攻撃の後のモンスターの体力は -2 です。

よって 3 回の攻撃でモンスターに勝つことができます。


入力例 2

1 10000

出力例 2

1

入力例 3

10000 1

出力例 3

10000

Score : 100 points

Problem Statement

Serval is fighting with a monster.

The health of the monster is H.

In one attack, Serval can decrease the monster's health by A. There is no other way to decrease the monster's health.

Serval wins when the monster's health becomes 0 or below.

Find the number of attacks Serval needs to make before winning.

Constraints

  • 1 \leq H \leq 10^4
  • 1 \leq A \leq 10^4
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

H A

Output

Print the number of attacks Serval needs to make before winning.


Sample Input 1

10 4

Sample Output 1

3
  • After one attack, the monster's health will be 6.
  • After two attacks, the monster's health will be 2.
  • After three attacks, the monster's health will be -2.

Thus, Serval needs to make three attacks to win.


Sample Input 2

1 10000

Sample Output 2

1

Sample Input 3

10000 1

Sample Output 3

10000
B - Common Raccoon vs Monster

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

アライグマはモンスターと戦っています。

モンスターの体力は H です。

アライグマは N 種類の必殺技を使うことができ、i 番目の必殺技を使うとモンスターの体力を A_i 減らすことができます。 必殺技を使う以外の方法でモンスターの体力を減らすことはできません。

モンスターの体力を 0 以下にすればアライグマの勝ちです。

アライグマが同じ必殺技を 2 度以上使うことなくモンスターに勝つことができるなら Yes を、できないなら No を出力してください。

制約

  • 1 \leq H \leq 10^9
  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq 10^4
  • 入力中のすべての値は整数である。

入力

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

H N
A_1 A_2 ... A_N

出力

アライグマが同じ必殺技を 2 度以上使うことなくモンスターに勝つことができるなら Yes を、できないなら No を出力せよ。


入力例 1

10 3
4 5 6

出力例 1

Yes

例えば 2 番目と 3 番目の必殺技を使うことで、モンスターの体力を 0 以下にできます。


入力例 2

20 3
4 5 6

出力例 2

No

入力例 3

210 5
31 41 59 26 53

出力例 3

Yes

入力例 4

211 5
31 41 59 26 53

出力例 4

No

Score : 200 points

Problem Statement

Raccoon is fighting with a monster.

The health of the monster is H.

Raccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i. There is no other way to decrease the monster's health.

Raccoon wins when the monster's health becomes 0 or below.

If Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.

Constraints

  • 1 \leq H \leq 10^9
  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq 10^4
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

H N
A_1 A_2 ... A_N

Output

If Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.


Sample Input 1

10 3
4 5 6

Sample Output 1

Yes

The monster's health will become 0 or below after, for example, using the second and third moves.


Sample Input 2

20 3
4 5 6

Sample Output 2

No

Sample Input 3

210 5
31 41 59 26 53

Sample Output 3

Yes

Sample Input 4

211 5
31 41 59 26 53

Sample Output 4

No
C - Fennec vs Monster

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

フェネックは N 体のモンスターと戦っています。

i 番目のモンスターの体力は H_i です。

フェネックは次の 2 種類の行動を行うことができます。

  • 攻撃:モンスターを 1 体選んで攻撃することで、そのモンスターの体力を 1 減らす
  • 必殺技:モンスターを 1 体選んで必殺技を使うことで、そのモンスターの体力を 0 にする

攻撃と必殺技以外の方法でモンスターの体力を減らすことはできません。

全てのモンスターの体力を 0 以下にすればフェネックの勝ちです。

フェネックが K 回まで必殺技を使えるとき、モンスターに勝つまでに行う攻撃の回数 (必殺技は数えません) の最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq K \leq 2 \times 10^5
  • 1 \leq H_i \leq 10^9
  • 入力中のすべての値は整数である。

入力

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

N K
H_1 ... H_N

出力

フェネックがモンスターに勝つまでに行う攻撃の回数 (必殺技は数えない) の最小値を出力せよ。


入力例 1

3 1
4 1 5

出力例 1

5

3 番目のモンスターに必殺技を使い、1 番目のモンスターに 4 回、2 番目のモンスターに 1 回攻撃を行うことで、攻撃の回数を 5 回にできます。


入力例 2

8 9
7 9 3 2 3 8 4 6

出力例 2

0

全てのモンスターに必殺技を使うことができます。


入力例 3

3 0
1000000000 1000000000 1000000000

出力例 3

3000000000

オーバーフローに注意してください。

Score : 300 points

Problem Statement

Fennec is fighting with N monsters.

The health of the i-th monster is H_i.

Fennec can do the following two actions:

  • Attack: Fennec chooses one monster. That monster's health will decrease by 1.
  • Special Move: Fennec chooses one monster. That monster's health will become 0.

There is no way other than Attack and Special Move to decrease the monsters' health.

Fennec wins when all the monsters' healths become 0 or below.

Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq K \leq 2 \times 10^5
  • 1 \leq H_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
H_1 ... H_N

Output

Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.


Sample Input 1

3 1
4 1 5

Sample Output 1

5

By using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.


Sample Input 2

8 9
7 9 3 2 3 8 4 6

Sample Output 2

0

She can use Special Move on all the monsters.


Sample Input 3

3 0
1000000000 1000000000 1000000000

Sample Output 3

3000000000

Watch out for overflow.

D - Caracal vs Monster

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

カラカルはモンスターと戦っています。

モンスターの体力は H です。

カラカルはモンスターを 1 体選んで攻撃することができます。モンスターを攻撃したとき、攻撃対象のモンスターの体力に応じて、次のどちらかが起こります。

  • モンスターの体力が 1 なら、そのモンスターの体力は 0 になる
  • モンスターの体力が X >1 なら、そのモンスターは消滅し、体力が \lfloor X/2 \rfloor のモンスターが新たに 2 体現れる

\lfloor r \rfloorr を超えない最大の整数を表す)

全てのモンスターの体力を 0 以下にすればカラカルの勝ちです。

カラカルがモンスターに勝つまでに行う攻撃の回数の最小値を求めてください。

制約

  • 1 \leq H \leq 10^{12}
  • 入力中のすべての値は整数である。

入力

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

H

出力

カラカルがモンスターに勝つまでに行う攻撃の回数の最小値を出力せよ。


入力例 1

2

出力例 1

3

モンスターを攻撃すると、元のモンスターは消滅し、体力 1 のモンスターが 2 体現れます。

この 2 体のモンスターをそれぞれ 1 回ずつ攻撃し、合計 3 回の攻撃で勝つことができます。


入力例 2

4

出力例 2

7

入力例 3

1000000000000

出力例 3

1099511627775

Score : 400 points

Problem Statement

Caracal is fighting with a monster.

The health of the monster is H.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

  • If the monster's health is 1, it drops to 0.
  • If the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \lfloor X/2 \rfloor.

(\lfloor r \rfloor denotes the greatest integer not exceeding r.)

Caracal wins when the healths of all existing monsters become 0 or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

  • 1 \leq H \leq 10^{12}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

H

Output

Find the minimum number of attacks Caracal needs to make before winning.


Sample Input 1

2

Sample Output 1

3

When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of 1.

Then, Caracal can attack each of these new monsters once and win with a total of three attacks.


Sample Input 2

4

Sample Output 2

7

Sample Input 3

1000000000000

Sample Output 3

1099511627775
E - Crested Ibis vs Monster

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

トキはモンスターと戦っています。

モンスターの体力は H です。

トキは N 種類の魔法が使え、i 番目の魔法を使うと、モンスターの体力を A_i 減らすことができますが、トキの魔力を B_i 消耗します。

同じ魔法は何度でも使うことができます。魔法以外の方法でモンスターの体力を減らすことはできません。

モンスターの体力を 0 以下にすればトキの勝ちです。

トキがモンスターに勝つまでに消耗する魔力の合計の最小値を求めてください。

制約

  • 1 \leq H \leq 10^4
  • 1 \leq N \leq 10^3
  • 1 \leq A_i \leq 10^4
  • 1 \leq B_i \leq 10^4
  • 入力中のすべての値は整数である。

入力

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

H N
A_1 B_1
:
A_N B_N

出力

トキがモンスターに勝つまでに消耗する魔力の最小値を出力せよ。


入力例 1

9 3
8 3
4 2
2 1

出力例 1

4

最初に 1 番目の魔法を使い、トキの魔力を 3 消耗して、モンスターの体力を 8 減らします。モンスターの体力は 1 になります。

次に 3 番目の魔法を使い、トキの魔力を 1 消耗して、モンスターの体力を 2 減らします。モンスターの体力は -1 になります。

これにより、トキが消耗した魔力の合計は 4 になります。


入力例 2

100 6
1 1
2 3
3 9
4 27
5 81
6 243

出力例 2

100

1 番目の魔法を 100 回使うのが最適です。


入力例 3

9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461

出力例 3

139815

Score : 500 points

Problem Statement

Ibis is fighting with a monster.

The health of the monster is H.

Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points.

The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health.

Ibis wins when the health of the monster becomes 0 or below.

Find the minimum total Magic Points that have to be consumed before winning.

Constraints

  • 1 \leq H \leq 10^4
  • 1 \leq N \leq 10^3
  • 1 \leq A_i \leq 10^4
  • 1 \leq B_i \leq 10^4
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

H N
A_1 B_1
:
A_N B_N

Output

Print the minimum total Magic Points that have to be consumed before winning.


Sample Input 1

9 3
8 3
4 2
2 1

Sample Output 1

4

First, let us cast the first spell to decrease the monster's health by 8, at the cost of 3 Magic Points. The monster's health is now 1.

Then, cast the third spell to decrease the monster's health by 2, at the cost of 1 Magic Point. The monster's health is now -1.

In this way, we can win at the total cost of 4 Magic Points.


Sample Input 2

100 6
1 1
2 3
3 9
4 27
5 81
6 243

Sample Output 2

100

It is optimal to cast the first spell 100 times.


Sample Input 3

9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461

Sample Output 3

139815
F - Silver Fox vs Monster

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

ギンギツネは N 体のモンスターと戦っています。

モンスターは 1 列に並んでおり、数直線上にいるとみなすことができます。i 番目のモンスターは座標 X_i にいて、体力は H_i です。

ギンギツネは爆弾を使ってモンスターを攻撃することができます。 座標 x で爆弾を使うと、座標が x-D 以上 x+D 以下の範囲にいる全てのモンスターの体力を A 減らすことができます。 爆弾を使う以外の方法でモンスターの体力を減らすことはできません。

全てのモンスターの体力を 0 以下にすればギンギツネの勝ちです。

ギンギツネがモンスターに勝つまでに爆弾を使う回数の最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq D \leq 10^9
  • 1 \leq A \leq 10^9
  • 0 \leq X_i \leq 10^9
  • 1 \leq H_i \leq 10^9
  • X_i は相異なる。
  • 入力中のすべての値は整数である。

入力

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

N D A
X_1 H_1
:
X_N H_N

出力

ギンギツネがモンスターに勝つまでに爆弾を使う回数の最小値を出力せよ。


入力例 1

3 3 2
1 2
5 4
9 2

出力例 1

2

最初に座標 4 で爆弾を使うことで、1 番目と 2 番目のモンスターの体力を 2 減らせます。

次に座標 6 で爆弾を使うことで、2 番目と 3 番目のモンスターの体力を 2 減らせます。

この 2 回で全てのモンスターの体力を 0 にできました。1 回で全てのモンスターの体力を 0 以下にすることはできません。


入力例 2

9 4 1
1 5
2 4
3 3
4 2
5 1
6 2
7 3
8 4
9 5

出力例 2

5

座標 5 で爆弾を 5 回使います。


入力例 3

3 0 1
300000000 1000000000
100000000 1000000000
200000000 1000000000

出力例 3

3000000000

オーバーフローに注意してください。

Score : 600 points

Problem Statement

Silver Fox is fighting with N monsters.

The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the health of H_i.

Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A. There is no way other than bombs to decrease the monster's health.

Silver Fox wins when all the monsters' healths become 0 or below.

Find the minimum number of bombs needed to win.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq D \leq 10^9
  • 1 \leq A \leq 10^9
  • 0 \leq X_i \leq 10^9
  • 1 \leq H_i \leq 10^9
  • X_i are distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D A
X_1 H_1
:
X_N H_N

Output

Print the minimum number of bombs needed to win.


Sample Input 1

3 3 2
1 2
5 4
9 2

Sample Output 1

2

First, let us use a bomb at the coordinate 4 to decrease the first and second monsters' health by 2.

Then, use a bomb at the coordinate 6 to decrease the second and third monsters' health by 2.

Now, all the monsters' healths are 0. We cannot make all the monsters' health drop to 0 or below with just one bomb.


Sample Input 2

9 4 1
1 5
2 4
3 3
4 2
5 1
6 2
7 3
8 4
9 5

Sample Output 2

5

We should use five bombs at the coordinate 5.


Sample Input 3

3 0 1
300000000 1000000000
100000000 1000000000
200000000 1000000000

Sample Output 3

3000000000

Watch out for overflow.