A - Battery Level and Charger Arrival

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

高橋君は N 台のスマートフォンを管理しています。i 番目のスマートフォンの現在のバッテリー残量は W_i パーセントです。

スマートフォンのバッテリーは、充電しなければ 1 日経過するごとに D パーセントポイントずつ減少します。

高橋君は充電器の通販サイトで注文を検討しています。注文すると、ちょうど K 日後に充電器が届きます。現在、高橋君の手元には充電器がないため、届くまでの K 日間は一切充電ができません。

K 日後、充電器が届いた時点での i 番目のスマートフォンのバッテリー残量を W_i - D \times K パーセントとみなします。この値が 1 以上であるスマートフォンは使える状態で残っており、そうでないスマートフォンは電源が切れて使えなくなっているものとします。

N 台のスマートフォンのうち、K 日後に使える状態で残っているものの台数を求めてください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq D \leq 100
  • 1 \leq K \leq 10^9
  • 1 \leq W_i \leq 100 (1 \leq i \leq N)
  • 入力はすべて整数

入力

N D K
W_1 W_2 \ldots W_N
  • 1 行目には、スマートフォンの台数を表す整数 N1 日あたりのバッテリー減少量を表す整数 D 、充電器が届くまでの日数を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各スマートフォンの現在のバッテリー残量を表す整数 W_1, W_2, \ldots, W_N が、スペース区切りで与えられる。

出力

K 日後に使える状態で残っているスマートフォンの台数を 1 行で出力してください。


入力例 1

3 10 5
100 50 30

出力例 1

1

入力例 2

5 15 3
80 45 46 20 100

出力例 2

3

入力例 3

10 7 10
100 70 71 50 35 28 1 72 99 65

出力例 3

4

Score : 200 pts

Problem Statement

Takahashi manages N smartphones. The current battery level of the i-th smartphone is W_i percent.

The battery of a smartphone decreases by D percentage points per day if not charged.

Takahashi is considering ordering from an online charger store. If he places an order, the charger will arrive in exactly K days. Since Takahashi currently has no charger, he cannot charge any smartphone during the K days until it arrives.

After K days, when the charger arrives, the battery level of the i-th smartphone is considered to be W_i - D \times K percent. A smartphone with this value being 1 or more is still usable, while a smartphone with this value less than 1 has powered off and become unusable.

Determine the number of smartphones among the N that are still usable after K days.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq D \leq 100
  • 1 \leq K \leq 10^9
  • 1 \leq W_i \leq 100 (1 \leq i \leq N)
  • All inputs are integers

Input

N D K
W_1 W_2 \ldots W_N
  • The first line contains the integer N representing the number of smartphones, the integer D representing the daily battery decrease, and the integer K representing the number of days until the charger arrives, separated by spaces.
  • The second line contains the integers W_1, W_2, \ldots, W_N representing the current battery levels of each smartphone, separated by spaces.

Output

Output in one line the number of smartphones that are still usable after K days.


Sample Input 1

3 10 5
100 50 30

Sample Output 1

1

Sample Input 2

5 15 3
80 45 46 20 100

Sample Output 2

3

Sample Input 3

10 7 10
100 70 71 50 35 28 1 72 99 65

Sample Output 3

4
B - Target Score for the Test

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 233

問題文

高橋君は N 科目の期末テストを受けました。各科目 i1 \leq i \leq N)において、高橋君は A_i 点を獲得しました。

高橋君の学校では、点数が目標点 T 点未満の科目が 1 科目でもあると、補習を受けなければなりません。

幸いなことに、この学校には「追加課題制度」があります。追加課題を 1 つ提出するごとに、好きな 1 科目を選んでその科目の点数を 1 点上げることができます。同じ科目を何度選んでもかまいません。また、各科目の点数に上限はありません。ただし、提出できる追加課題の数は合計で M 個以下です。追加課題を 1 つも提出しないことも許されます。

高橋君は、追加課題をうまく提出することで、すべての科目の点数を T 点以上にして補習を回避したいと考えています。

合計 M 個以下の追加課題の提出により、すべての科目で T 点以上を達成することが可能かどうかを判定してください。可能な場合は、そのために必要な追加課題の最小個数を出力してください。すでにすべての科目が T 点以上であれば 0 を出力してください。不可能な場合は -1 を出力してください。

制約

  • 1 \leq N \leq 10^5
  • 0 \leq M \leq 10^9
  • 0 \leq T \leq 100
  • 0 \leq A_i \leq 100 (1 \leq i \leq N)
  • 入力はすべて整数

入力

N M T
A_1 A_2 \ldots A_N
  • 1 行目には、科目数を表す整数 N 、提出できる追加課題の個数の上限を表す整数 M 、目標点を表す整数 T が、スペース区切りで与えられる。
  • 2 行目には、各科目で高橋君が獲得した点数を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。

出力

すべての科目で T 点以上を達成することが可能な場合は、必要な追加課題の最小個数を 1 行で出力してください。不可能な場合は -11 行で出力してください。


入力例 1

3 5 60
55 70 58

出力例 1

-1

入力例 2

5 10 80
75 80 90 60 85

出力例 2

-1

入力例 3

10 1000000000 70
65 70 72 68 55 80 90 45 70 71

出力例 3

47

Score : 233 pts

Problem Statement

Takahashi took final exams in N subjects. In each subject i (1 \leq i \leq N), Takahashi scored A_i points.

At Takahashi's school, if there is even one subject where the score is below the target score of T points, the student must attend supplementary lessons.

Fortunately, this school has an "extra assignment system." For each extra assignment submitted, Takahashi can choose any one subject and increase that subject's score by 1 point. The same subject may be chosen multiple times. There is no upper limit on the score for each subject. However, the total number of extra assignments that can be submitted is at most M. It is also allowed to submit no extra assignments at all.

Takahashi wants to avoid supplementary lessons by strategically submitting extra assignments so that all subjects' scores become at least T points.

Determine whether it is possible to achieve a score of at least T in all subjects by submitting a total of at most M extra assignments. If it is possible, output the minimum number of extra assignments needed. If all subjects already have scores of at least T, output 0. If it is impossible, output -1.

Constraints

  • 1 \leq N \leq 10^5
  • 0 \leq M \leq 10^9
  • 0 \leq T \leq 100
  • 0 \leq A_i \leq 100 (1 \leq i \leq N)
  • All input values are integers.

Input

N M T
A_1 A_2 \ldots A_N
  • The first line contains three space-separated integers: N representing the number of subjects, M representing the maximum number of extra assignments that can be submitted, and T representing the target score.
  • The second line contains space-separated integers A_1, A_2, \ldots, A_N representing the scores Takahashi obtained in each subject.

Output

If it is possible to achieve a score of at least T in all subjects, output the minimum number of extra assignments needed on a single line. If it is impossible, output -1 on a single line.


Sample Input 1

3 5 60
55 70 58

Sample Output 1

-1

Sample Input 2

5 10 80
75 80 90 60 85

Sample Output 2

-1

Sample Input 3

10 1000000000 70
65 70 72 68 55 80 90 45 70 71

Sample Output 3

47
C - Road Pothole Survey

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 333

問題文

高橋君は市役所の道路管理課で働いています。管轄する道路の路面は N 枚のタイルが一列に並んで構成されており、左から順にタイル 1, 2, \ldots, N と番号がついています。

このうち M 枚のタイルは損傷しています。損傷したタイルの番号は B_1, B_2, \ldots, B_M で、これらはすべて異なります(昇順とは限りません)。

ある日、K 台の車がこの道路を通行しました。i 番目の車(1 \leq i \leq K)はタイル L_i からタイル R_i まで(L_i \leq R_i)の連続する区間に含まれるすべてのタイルをちょうど 1 回ずつ通過します。各車の通行は他の車の通行に影響を与えず、また車が通過してもタイルの状態は変化しません。

車が損傷したタイルを 1 枚通過するごとに衝撃が 1 回発生します。すなわち、i 番目の車の通行で発生する衝撃の合計回数は、タイル L_i からタイル R_i までの区間に含まれる損傷したタイルの枚数に等しくなります。

高橋君は、各車について通行で発生した衝撃の合計回数を求め、それが閾値 T 以上であれば、その車の通行区間を「要修繕」として報告します。ここで T は正の整数として与えられます。

K 台の車それぞれについて、その通行区間が要修繕として報告されるかどうかを判定してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq N
  • 1 \leq K \leq 2 \times 10^5
  • 1 \leq T \leq N
  • 1 \leq B_i \leq N1 \leq i \leq M
  • B_i はすべて異なる
  • 1 \leq L_i \leq R_i \leq N1 \leq i \leq K
  • 入力はすべて整数

入力

N M K T
B_1 B_2 \ldots B_M
L_1 R_1
L_2 R_2
\vdots
L_K R_K
  • 1 行目には、タイルの総枚数 N 、損傷したタイルの枚数 M 、車の台数 K 、衝撃回数の閾値 T がスペース区切りで与えられる。
  • 2 行目には、損傷したタイルの番号 B_1, B_2, \ldots, B_M がスペース区切りで与えられる。昇順とは限らない。
  • 3 行目から K 行にわたって、各車の通行区間が与えられる。
  • 2 + i 行目には、i 番目の車の通行区間の左端 L_i と右端 R_i がスペース区切りで与えられる。

出力

K 行出力せよ。i 行目には、i 番目の車の通行区間が要修繕として報告される場合は YES を、そうでない場合は NO を出力せよ。


入力例 1

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

出力例 1

YES
NO
YES

入力例 2

5 1 3 2
3
1 2
3 3
1 5

出力例 2

NO
NO
NO

入力例 3

20 6 8 3
3 7 10 12 15 18
1 20
1 5
5 15
10 18
1 2
14 16
6 13
11 14

出力例 3

YES
NO
YES
YES
NO
NO
YES
NO

入力例 4

50 10 12 4
31 5 44 17 28 12 49 36 23 40
1 50
1 10
10 30
20 45
1 4
5 5
30 50
15 25
35 50
1 28
43 46
25 42

出力例 4

YES
NO
YES
YES
NO
NO
YES
NO
YES
YES
NO
YES

入力例 5

1 1 1 1
1
1 1

出力例 5

YES

Score : 333 pts

Problem Statement

Takahashi works at the road management division of the city hall. The road surface under his jurisdiction consists of N tiles arranged in a row, numbered tile 1, 2, \ldots, N from left to right.

Among these, M tiles are damaged. The numbers of the damaged tiles are B_1, B_2, \ldots, B_M, all of which are distinct (not necessarily in ascending order).

One day, K cars traveled along this road. The i-th car (1 \leq i \leq K) passes over every tile exactly once in the contiguous section from tile L_i to tile R_i (L_i \leq R_i). Each car's travel does not affect the travel of other cars, and tiles do not change their state when a car passes over them.

Each time a car passes over one damaged tile, one shock occurs. That is, the total number of shocks generated by the i-th car's travel equals the number of damaged tiles contained in the section from tile L_i to tile R_i.

For each car, Takahashi calculates the total number of shocks generated during its travel, and if it is at least the threshold T, he reports that car's travel section as "needs repair." Here, T is given as a positive integer.

For each of the K cars, determine whether its travel section is reported as needing repair.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq N
  • 1 \leq K \leq 2 \times 10^5
  • 1 \leq T \leq N
  • 1 \leq B_i \leq N (1 \leq i \leq M)
  • All B_i are distinct
  • 1 \leq L_i \leq R_i \leq N (1 \leq i \leq K)
  • All input values are integers

Input

N M K T
B_1 B_2 \ldots B_M
L_1 R_1
L_2 R_2
\vdots
L_K R_K
  • The first line contains the total number of tiles N, the number of damaged tiles M, the number of cars K, and the shock count threshold T, separated by spaces.
  • The second line contains the numbers of the damaged tiles B_1, B_2, \ldots, B_M, separated by spaces. They are not necessarily in ascending order.
  • The following K lines give the travel section of each car.
  • The (2 + i)-th line contains the left endpoint L_i and right endpoint R_i of the i-th car's travel section, separated by spaces.

Output

Output K lines. On the i-th line, print YES if the i-th car's travel section is reported as needing repair, and NO otherwise.


Sample Input 1

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

Sample Output 1

YES
NO
YES

Sample Input 2

5 1 3 2
3
1 2
3 3
1 5

Sample Output 2

NO
NO
NO

Sample Input 3

20 6 8 3
3 7 10 12 15 18
1 20
1 5
5 15
10 18
1 2
14 16
6 13
11 14

Sample Output 3

YES
NO
YES
YES
NO
NO
YES
NO

Sample Input 4

50 10 12 4
31 5 44 17 28 12 49 36 23 40
1 50
1 10
10 30
20 45
1 4
5 5
30 50
15 25
35 50
1 28
43 46
25 42

Sample Output 4

YES
NO
YES
YES
NO
NO
YES
NO
YES
YES
NO
YES

Sample Input 5

1 1 1 1
1
1 1

Sample Output 5

YES
D - Simultaneous Control of Light Bulb Panels

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

高橋君は N 個の電球が一列に並んだ装飾パネルを持っています。それぞれの電球には左から順に 1 から N までの番号が付けられており、各電球は「点灯」か「消灯」のどちらかの状態になっています。

各電球の初期状態は整数 A_i で与えられます。A_i = 0 のとき電球 i点灯しており、A_i = 1 のとき電球 i消灯しています。

高橋君は以下の操作を好きな回数( 0 回でも可)行うことができます。

  • 整数 i1 \leq i \leq N - K + 1)を 1 つ選び、電球 i, i+1, \ldots, i+K-1 の状態をすべて反転させる。すなわち、この連続する K 個の電球のうち、点灯していたものは消灯し、消灯していたものは点灯する。

各操作で選ぶ i の値は毎回自由に決めることができ、以前と同じ値を再び選ぶこともできます。

高橋君は、すべての電球を点灯状態(すなわち、すべての i に対して A_i = 0 の状態)にしたいと考えています。これが可能かどうかを判定し、可能な場合は必要な最小操作回数を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq N
  • A_i \in \{0, 1\} (1 \leq i \leq N)
  • 入力はすべて整数である

入力

N K
A_1 A_2 \ldots A_N
  • 1 行目には、電球の個数を表す整数 N と、1 回の操作で反転させる電球の個数を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各電球の初期状態を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
  • A_i = 0 のとき、電球 i は点灯している。
  • A_i = 1 のとき、電球 i は消灯している。

出力

すべての電球を点灯状態にすることが可能な場合は、必要な最小操作回数を 1 行で出力してください。

不可能な場合は、-11 行で出力してください。


入力例 1

5 3
0 1 1 1 0

出力例 1

1

入力例 2

4 2
1 0 0 1

出力例 2

3

入力例 3

10 3
1 1 1 0 0 0 1 1 1 0

出力例 3

2

Score : 400 pts

Problem Statement

Takahashi has a decorative panel with N light bulbs arranged in a row. The bulbs are numbered from 1 to N from left to right, and each bulb is in one of two states: "on" or "off".

The initial state of each bulb is given by an integer A_i. When A_i = 0, bulb i is on, and when A_i = 1, bulb i is off.

Takahashi can perform the following operation any number of times (possibly zero):

  • Choose an integer i (1 \leq i \leq N - K + 1) and toggle the states of bulbs i, i+1, \ldots, i+K-1. That is, among these K consecutive bulbs, those that are on are turned off, and those that are off are turned on.

The value of i chosen in each operation can be decided freely each time, and it is allowed to choose the same value as before.

Takahashi wants to turn all bulbs on (that is, reach the state where A_i = 0 for all i). Determine whether this is possible, and if so, find the minimum number of operations required.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq N
  • A_i \in \{0, 1\} (1 \leq i \leq N)
  • All inputs are integers

Input

N K
A_1 A_2 \ldots A_N
  • The first line contains an integer N representing the number of bulbs and an integer K representing the number of bulbs toggled in one operation, separated by a space.
  • The second line contains integers A_1, A_2, \ldots, A_N representing the initial state of each bulb, separated by spaces.
  • When A_i = 0, bulb i is on.
  • When A_i = 1, bulb i is off.

Output

If it is possible to turn all bulbs on, output the minimum number of operations required in one line.

If it is impossible, output -1 in one line.


Sample Input 1

5 3
0 1 1 1 0

Sample Output 1

1

Sample Input 2

4 2
1 0 0 1

Sample Output 2

3

Sample Input 3

10 3
1 1 1 0 0 0 1 1 1 0

Sample Output 3

2
E - Delivery Driver's Route

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 433

問題文

ある地域には N 個の町があり、町には 1 から N までの番号が付けられています。いくつかの町の間には道路が整備されており、道路はすべて双方向に通行可能で、全部で M 本あります。i 番目の道路は町 U_i と町 V_i を結んでおり、この道路を通って移動するのにかかる時間は W_i です。なお、すべての町が道路で互いに行き来できるとは限りません。

高橋君は配達ドライバーであり、町 1 にある配送センターから出発して、N 個すべての町に荷物を届けた後、町 1 の配送センターに戻ってこなければなりません。具体的には、町 1 から出発し、道路を通って町から町へ移動することを繰り返して、すべての町を少なくとも 1 回ずつ訪問し、最終的に町 1 に戻る経路をとります。同じ町を複数回訪問したり、同じ道路を複数回通ったりすることは許されます。

このような経路における、通った道路の移動時間の総和の最小値を求めてください。同じ道路を複数回通った場合は、通るたびにその道路の移動時間が加算されます。条件を満たす経路が存在しない場合は -1 を出力してください。

制約

  • 2 \leq N \leq 15
  • 1 \leq M \leq \frac{N(N-1)}{2}
  • 1 \leq U_i, V_i \leq N
  • U_i \neq V_i(自己ループはない)
  • i \neq j ならば \{U_i, V_i\} \neq \{U_j, V_j\}(同じ町の組を結ぶ道路は高々 1 本)
  • 1 \leq W_i \leq 10^6
  • 入力はすべて整数である

入力

N M
U_1 V_1 W_1
U_2 V_2 W_2
\vdots
U_M V_M W_M
  • 1 行目には、町の数 N と道路の数 M がスペース区切りで与えられる。
  • 続く M 行では、各道路の情報が与えられる。そのうち i 行目では、i 番目の道路が結ぶ 2 つの町の番号 U_i, V_i と、その道路の移動時間 W_i がスペース区切りで与えられる。

出力

高橋君がすべての町を少なくとも 1 回ずつ訪問し、町 1 に戻るために必要な移動時間の総和の最小値を 1 行で出力せよ。条件を満たす経路が存在しない場合は -1 を出力せよ。


入力例 1

4 4
1 2 10
2 3 15
3 4 20
4 1 25

出力例 1

70

入力例 2

4 2
1 2 5
3 4 8

出力例 2

-1

入力例 3

6 7
1 2 3
1 3 10
2 3 4
2 4 7
3 5 2
4 6 5
5 6 6

出力例 3

30

Score : 433 pts

Problem Statement

There are N towns in a region, numbered from 1 to N. Some towns are connected by roads, all of which are bidirectional, and there are M roads in total. The i-th road connects town U_i and town V_i, and the time required to travel along this road is W_i. Note that it is not necessarily the case that all towns are reachable from each other via roads.

Takahashi is a delivery driver. He must depart from the distribution center located in town 1, deliver packages to all N towns, and then return to the distribution center in town 1. Specifically, he starts from town 1, repeatedly moves from town to town via roads, visits every town at least once, and finally returns to town 1. He is allowed to visit the same town multiple times and traverse the same road multiple times.

Find the minimum total travel time of roads traversed along such a route. If the same road is traversed multiple times, its travel time is added each time it is traversed. If no valid route exists, output -1.

Constraints

  • 2 \leq N \leq 15
  • 1 \leq M \leq \frac{N(N-1)}{2}
  • 1 \leq U_i, V_i \leq N
  • U_i \neq V_i (no self-loops)
  • If i \neq j, then \{U_i, V_i\} \neq \{U_j, V_j\} (there is at most one road between any pair of towns)
  • 1 \leq W_i \leq 10^6
  • All input values are integers

Input

N M
U_1 V_1 W_1
U_2 V_2 W_2
\vdots
U_M V_M W_M
  • The first line contains the number of towns N and the number of roads M, separated by a space.
  • The following M lines each contain information about a road. The i-th of these lines contains the numbers of the two towns U_i, V_i connected by the i-th road, and the travel time W_i of that road, separated by spaces.

Output

Output in a single line the minimum total travel time required for Takahashi to visit every town at least once and return to town 1. If no valid route exists, output -1.


Sample Input 1

4 4
1 2 10
2 3 15
3 4 20
4 1 25

Sample Output 1

70

Sample Input 2

4 2
1 2 5
3 4 8

Sample Output 2

-1

Sample Input 3

6 7
1 2 3
1 3 10
2 3 4
2 4 7
3 5 2
4 6 5
5 6 6

Sample Output 3

30