E - Virus

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

1, 2, \ldots, N の番号がついた N 人の人が二次元平面上におり、人 i は座標 (X_i,Y_i) で表される地点にいます。

1 がウイルスに感染しました。ウイルスに感染した人から距離が D 以内にいる人にウイルスはうつります。

ただし、距離はユークリッド距離、すなわち 2(a_1, a_2)(b_1, b_2) に対し、この 2 点間の距離が \sqrt {(a_1-b_1)^2 + (a_2-b_2)^2} であるものとして定められています。

十分に時間が経過した、すなわち人 i がウイルスに感染しているならば 人 i との距離が D 以内にいるすべての人がウイルスに感染している状態になったときに、各 i について人 i がウイルスに感染しているか判定してください。

制約

  • 1 \leq N, D \leq 2000
  • -1000 \leq X_i, Y_i \leq 1000
  • i \neq j のとき (X_i, Y_i) \neq (X_j, Y_j)
  • 入力はすべて整数

入力

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

N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

出力

N 行出力せよ。i 行目には、人 i がウイルスに感染しているならば Yes を、そうでないならば No を出力せよ。


入力例 1

4 5
2 -1
3 1
8 8
0 5

出力例 1

Yes
Yes
No
Yes

1 と人 2 の距離は \sqrt 5 であるため、人 2 はウイルスに感染します。
また、人 2 と人 4 の距離は 5 であるため、人 4 はウイルスに感染します。
3 は距離 5 以内に人がいないので、ウイルスに感染することはありません。


入力例 2

3 1
0 0
-1000 -1000
1000 1000

出力例 2

Yes
No
No

入力例 3

9 4
3 2
6 -1
1 6
6 5
-2 -3
5 3
2 -3
2 1
2 6

出力例 3

Yes
No
No
Yes
Yes
Yes
Yes
Yes
No

Score : 300 points

Problem Statement

There are N people numbered 1, 2, \ldots, N on a two-dimensional plane, and person i is at the point represented by the coordinates (X_i,Y_i).

Person 1 has been infected with a virus. The virus spreads to people within a distance of D from an infected person.

Here, the distance is defined as the Euclidean distance, that is, for two points (a_1, a_2) and (b_1, b_2), the distance between these two points is \sqrt {(a_1-b_1)^2 + (a_2-b_2)^2}.

After a sufficient amount of time has passed, that is, when all people within a distance of D from person i are infected with the virus if person i is infected, determine whether person i is infected with the virus for each i.

Constraints

  • 1 \leq N, D \leq 2000
  • -1000 \leq X_i, Y_i \leq 1000
  • (X_i, Y_i) \neq (X_j, Y_j) if i \neq j.
  • All input values are integers.

Input

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

N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

Output

Print N lines. The i-th line should contain Yes if person i is infected with the virus, and No otherwise.


Sample Input 1

4 5
2 -1
3 1
8 8
0 5

Sample Output 1

Yes
Yes
No
Yes

The distance between person 1 and person 2 is \sqrt 5, so person 2 gets infected with the virus.
Also, the distance between person 2 and person 4 is 5, so person 4 gets infected with the virus.
Person 3 has no one within a distance of 5, so they will not be infected with the virus.


Sample Input 2

3 1
0 0
-1000 -1000
1000 1000

Sample Output 2

Yes
No
No

Sample Input 3

9 4
3 2
6 -1
1 6
6 5
-2 -3
5 3
2 -3
2 1
2 6

Sample Output 3

Yes
No
No
Yes
Yes
Yes
Yes
Yes
No
F - Cash Register

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

高橋君は、レジ打ちの仕事をしています。

レジの機械には 00, 0, 1, 2, 3, 4, 5, 6, 7, 8, 911 個のボタンがあります。 レジの機械には、はじめ 0 が表示されています。 ボタン 00 を押すと、表示されている数が 100 倍されます。 それ以外のボタンを押すと、表示されている数が 10 倍されたあとに、押されたボタンに書かれている数が加算されます。

高橋君は、レジに整数 S を表示させたいです。 レジに S が表示されている状態にするためには、少なくとも何回ボタンを押す必要があるか求めてください。

制約

  • 1\leq S\leq 10^{100000}
  • S は整数

入力

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

S

出力

答えを 1 行で出力せよ。


入力例 1

40004

出力例 1

4

例えば、次のように操作することでボタンを 4 回押して 40004 を表示させることができます。 はじめ、レジには 0 が表示されています。

  • ボタン 4 を押す。レジに表示されている数は 4 となる。
  • ボタン 00 を押す。レジに表示されている数は 400 となる。
  • ボタン 0 を押す。レジに表示されている数は 4000 となる。
  • ボタン 4 を押す。レジに表示されている数は 40004 となる。

3 回までボタンを押すことでレジに 40004 を表示させることはできないので、出力すべき値は 4 です。


入力例 2

1355506027

出力例 2

10

入力例 3

10888869450418352160768000001

出力例 3

27

S64\operatorname{bit} 整数に収まらない場合があることに注意してください。

Score : 300 points

Problem Statement

Takahashi is a cashier.

There is a cash register with 11 keys: 00, 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. The cash register initially displays 0. Whenever he types the key 00, the displayed number is multiplied by 100; whenever he types one of the others, the displayed number is multiplied by 10, and then added by the number written on the key.

Takahashi wants the cash register to display an integer S. At least how many keystrokes are required to make it display S?

Constraints

  • 1\leq S\leq 10^{100000}
  • S is an integer.

Input

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

S

Output

Print the answer in a line.


Sample Input 1

40004

Sample Output 1

4

For example, the following four keystrokes make the cash register display 40004. Initially, the cash register displays 0.

  • Type the key 4. It now displays 4.
  • Type the key 00. It now displays 400.
  • Type the key 0. It now displays 4000.
  • Type the key 4. It now displays 40004.

He cannot make it display 40004 with three or fewer keystrokes, so 4 should be printed.


Sample Input 2

1355506027

Sample Output 2

10

Sample Input 3

10888869450418352160768000001

Sample Output 3

27

Note that S may not fit into a 64-\operatorname{bit} integer type.

G - Printing Machine

Time Limit: 3 sec / Memory Limit: 1024 MiB

配点 : 450

問題文

1 から N までの番号が付けられた N 個の商品がベルトコンベア上を流れています。 ベルトコンベアには印字機が取り付けられており、商品 i は今から T_i [μs] 後に印字機の範囲に入り、その D_i [μs] 後に印字機の範囲から出ます。

キーエンスの印字機は、印字機の範囲内にある商品 1 つに一瞬で印字することができます(特に、商品が印字機の範囲に入る瞬間や範囲から出る瞬間に印字することも可能です)。 ただし、1 度印字すると、次に印字するまでに 1 [μs] のチャージ時間が必要です。 印字機が印字をする商品とタイミングをうまく選んだとき、最大で何個の商品に印字することができますか?

制約

  • 1\leq N \leq 2\times 10^5
  • 1\leq T_i,D_i \leq 10^{18}
  • 入力は全て整数

入力

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

N
T_1 D_1
T_2 D_2
\vdots
T_N D_N

出力

印字機が印字することのできる商品の数の最大値を出力せよ。


入力例 1

5
1 1
1 1
2 1
1 2
1 4

出力例 1

4

以下、今から t [μs] 後のことを単に時刻 t とよびます。

例えば、次のようにして 4 個の商品に印字することができます。

  • 時刻 1 : 商品 1,2,4,5 が印字機の範囲に入る。商品 4 に印字する。
  • 時刻 2 : 商品 3 が印字機の範囲に入り、商品 1,2 が印字機の範囲から出る。商品 1 に印字する。
  • 時刻 3 : 商品 3,4 が印字機の範囲から出る。商品 3 に印字する。
  • 時刻 4.5 : 商品 5 に印字する。
  • 時刻 5 : 商品 5 が印字機の範囲から出る。

5 個の商品すべてに印字することはできないため、答えは 4 です。


入力例 2

2
1 1
1000000000000000000 1000000000000000000

出力例 2

2

入力例 3

10
4 1
1 2
1 4
3 2
5 1
5 1
4 1
2 1
4 1
2 4

出力例 3

6

Score : 450 points

Problem Statement

There are N products labeled 1 to N flowing on a conveyor belt. A Keyence printer is attached to the conveyor belt, and product i enters the range of the printer T_i microseconds from now and leaves it D_i microseconds later.

The Keyence printer can instantly print on one product within the range of the printer (in particular, it is possible to print at the moment the product enters or leaves the range of the printer). However, after printing once, it requires a charge time of 1 microseconds before it can print again. What is the maximum number of products the printer can print on when the product and timing for the printer to print are chosen optimally?

Constraints

  • 1\leq N \leq 2\times 10^5
  • 1\leq T_i,D_i \leq 10^{18}
  • All input values are integers.

Input

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

N
T_1 D_1
T_2 D_2
\vdots
T_N D_N

Output

Print the maximum number of products the printer can print on.


Sample Input 1

5
1 1
1 1
2 1
1 2
1 4

Sample Output 1

4

Below, we will simply call the moment t microseconds from now time t.

For example, you can print on four products as follows:

  • Time 1 : Products 1,2,4,5 enter the range of the printer. Print on product 4.
  • Time 2 : Product 3 enters the range of the printer, and products 1,2 leave the range of the printer. Print on product 1.
  • Time 3 : Products 3,4 leave the range of the printer. Print on product 3.
  • Time 4.5 : Print on product 5.
  • Time 5 : Product 5 leaves the range of the printer.

It is impossible to print on all five products, so the answer is 4.


Sample Input 2

2
1 1
1000000000000000000 1000000000000000000

Sample Output 2

2

Sample Input 3

10
4 1
1 2
1 4
3 2
5 1
5 1
4 1
2 1
4 1
2 4

Sample Output 3

6
H - Wish List

Time Limit: 3 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

お店に N 個の商品が並んでおり、それらは商品 1 、商品 2\ldots 、商品 N と番号づけられています。
i = 1, 2, \ldots, N について、商品 i定価A_i 円です。また、各商品の在庫は 1 つです。

高橋君は、商品 X_1 、商品 X_2\ldots 、商品 X_MM 個の商品が欲しいです。

高橋君は、欲しい商品をすべて手に入れるまで、下記の行動を繰り返します。

現在売れ残っている商品の個数を r とする。 1 \leq j \leq r を満たす整数 j を選び、現在売れ残っている商品のうち番号が j 番目に小さい商品を、その定価C_j 円だけ加えた金額で購入する。

高橋君が欲しい商品をすべて手に入れるまでにかかる合計費用としてあり得る最小値を出力してください。

なお、高橋君は欲しい商品ではない商品を購入することもできます。

制約

  • 1 \leq M \leq N \leq 5000
  • 1 \leq A_i \leq 10^9
  • 1 \leq C_i \leq 10^9
  • 1 \leq X_1 \lt X_2 \lt \cdots \lt X_M \leq N
  • 入力はすべて整数

入力

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

N M
A_1 A_2 \ldots A_N
C_1 C_2 \ldots C_N
X_1 X_2 \ldots X_M

出力

答えを出力せよ。


入力例 1

5 2
3 1 4 1 5
9 2 6 5 3
3 5

出力例 1

17

高橋君は下記の手順で行動することで、欲しい商品をすべて手に入れるまでにかかる合計費用を最小にすることができます。

  • はじめ、商品 1, 2, 3, 4, 55 個の商品が売れ残っています。 高橋君は j = 5 を選び、売れ残っている商品のうち番号が 5 番目に小さい商品 5 を、A_5 + C_5 = 5 + 3 = 8 円で購入します。
  • その後、商品 1, 2, 3, 44 個の商品が売れ残っています。 高橋君は j = 2 を選び、売れ残っている商品のうち番号が 2 番目に小さい商品 2 を、A_2 + C_2 = 1 + 2 = 3 円で購入します。
  • その後、商品 1, 3, 43 個の商品が売れ残っています。 高橋君は j = 2 を選び、売れ残っている商品のうち番号が 2 番目に小さい商品 3 を、A_3 + C_2 = 4 + 2 = 6 円で購入します。

以上の手順によって、高橋君は欲しい商品である商品 3, 5 のすべて(および、欲しい商品ではない商品 2 )を手に入れることができ、 それまでにかかる合計費用は 8 + 3 + 6 = 17 円です。これが合計費用としてあり得る最小値です。


入力例 2

20 8
29 27 79 27 30 4 93 89 44 88 70 75 96 3 78 39 97 12 53 62
32 38 84 49 93 53 26 13 25 2 76 32 42 34 18 77 14 67 88 12
1 3 4 5 8 14 16 20

出力例 2

533

Score : 500 points

Problem Statement

There are N items in a shop, numbered as Item 1, Item 2, \ldots, Item N.
For each i = 1, 2, \ldots, N, the regular price of Item i is A_i yen. For each item, there is only one in stock.

Takahashi wants M items: Item X_1, Item X_2, \ldots, Item X_M.

He repeats the following until he gets all items he wants.

Let r be the number of unsold items now. Choose an integer j such that 1 \leq j \leq r, and buy the item with the j-th smallest item number among the unsold items, for its regular price plus C_j yen.

Print the smallest total amount of money needed to get all items Takahashi wants.

Takahashi may also buy items other than the ones he wants.

Constraints

  • 1 \leq M \leq N \leq 5000
  • 1 \leq A_i \leq 10^9
  • 1 \leq C_i \leq 10^9
  • 1 \leq X_1 \lt X_2 \lt \cdots \lt X_M \leq N
  • All values in the input are integers.

Input

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

N M
A_1 A_2 \ldots A_N
C_1 C_2 \ldots C_N
X_1 X_2 \ldots X_M

Output

Print the answer.


Sample Input 1

5 2
3 1 4 1 5
9 2 6 5 3
3 5

Sample Output 1

17

Here is a way for Takahashi to get all items he wants with the smallest total amount of money.

  • Initially, five items, Items 1, 2, 3, 4, 5, are remaining. Choose j = 5 to buy the item with the fifth smallest item number among the remaining, Item 5, for A_5 + C_5 = 5 + 3 = 8 yen.
  • Then, four items, Items 1, 2, 3, 4, are remaining. Choose j = 2 to buy the item with the second smallest item number among the remaining, Item 2, for A_2 + C_2 = 1 + 2 = 3 yen.
  • Then, three items, Items 1, 3, 4, are remaining. Choose j = 2 to buy the item with the second smallest item number among the remaining, Item 3, for A_3 + C_2 = 4 + 2 = 6 yen.

Now, Takahashi has all items he wants, Items 3 and 5, (along with Item 2, which is not wanted) for a total cost of 8 + 3 + 6 = 17 yen, the minimum possible.


Sample Input 2

20 8
29 27 79 27 30 4 93 89 44 88 70 75 96 3 78 39 97 12 53 62
32 38 84 49 93 53 26 13 25 2 76 32 42 34 18 77 14 67 88 12
1 3 4 5 8 14 16 20

Sample Output 2

533
I - Sum Sum Max

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

長さ M の整数列 A, B, C があります。

C は整数 x_1, \dots, x_N, y_1, \dots, y_N によって表されます。C の先頭 y_1 項は x_1 であり、続く y_2 項は x_2 であり、\ldots、末尾の y_N 項は x_N です。

BB_i = \sum_{k = 1}^i C_k \, (1 \leq i \leq M) によって定められます。

AA_i = \sum_{k = 1}^i B_k \, (1 \leq i \leq M) によって定められます。

A_1, \dots, A_M の最大値を求めてください。

T 個のテストケースが与えられるので、それぞれについて答えを求めてください。

制約

  • 1 \leq T \leq 2 \times 10^5
  • 1 \leq N \leq 2 \times 10^5
  • 1 つのファイルに含まれるテストケースについて、N の総和は 2 \times 10^5 以下
  • 1 \leq M \leq 10^9
  • |x_i| \leq 4 \, (1 \leq i \leq N)
  • y_i \gt 0 \, (1 \leq i \leq N)
  • \sum_{k = 1}^N y_k = M
  • 入力は全て整数

入力

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

T
\mathrm{case}_1
\vdots
\mathrm{case}_T

各テストケースは以下の形式で与えられる。

N M
x_1 y_1
\vdots
x_N y_N

出力

T 行出力せよ。i \, (1 \leq i \leq T) 行目には、i 個目のテストケースに対する答えを出力せよ。


入力例 1

3
3 7
-1 2
2 3
-3 2
10 472
-4 12
1 29
2 77
-1 86
0 51
3 81
3 17
-2 31
-4 65
4 23
1 1000000000
4 1000000000

出力例 1

4
53910
2000000002000000000

1 つ目のテストケースにおいて、

  • C = (-1, -1, 2, 2, 2, -3, -3)
  • B = (-1, -2, 0, 2, 4, 1, -2)
  • A = (-1, -3, -3, -1, 3, 4, 2)

であるので、A_1, \dots, A_M の最大値は 4 です。

Score : 500 points

Problem Statement

There are integer sequences A, B, C of length M each.

C is represented by integers x_1, \dots, x_N, y_1, \dots, y_N. The first y_1 terms of C are x_1, the subsequent y_2 terms are x_2, \ldots, the last y_N terms are x_N.

B is defined by B_i = \sum_{k = 1}^i C_k \, (1 \leq i \leq M).

A is defined by A_i = \sum_{k = 1}^i B_k \, (1 \leq i \leq M).

Find the maximum value among A_1, \dots, A_M.

You will be given T test cases to solve.

Constraints

  • 1 \leq T \leq 2 \times 10^5
  • 1 \leq N \leq 2 \times 10^5
  • The sum of N in a single file is at most 2 \times 10^5.
  • 1 \leq M \leq 10^9
  • |x_i| \leq 4 \, (1 \leq i \leq N)
  • y_i \gt 0 \, (1 \leq i \leq N)
  • \sum_{k = 1}^N y_k = M
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

T
\mathrm{case}_1
\vdots
\mathrm{case}_T

Each case is in the following format:

N M
x_1 y_1
\vdots
x_N y_N

Output

Print T lines. The i-th line (1 \leq i \leq T) should contain the answer to the i-th test case.


Sample Input 1

3
3 7
-1 2
2 3
-3 2
10 472
-4 12
1 29
2 77
-1 86
0 51
3 81
3 17
-2 31
-4 65
4 23
1 1000000000
4 1000000000

Sample Output 1

4
53910
2000000002000000000

In the first test case, we have:

  • C = (-1, -1, 2, 2, 2, -3, -3)
  • B = (-1, -2, 0, 2, 4, 1, -2)
  • A = (-1, -3, -3, -1, 3, 4, 2)

Thus, the maximum value among A_1, \dots, A_M is 4.