実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 233 点
問題文
高橋君は、ある国の税金計算システムを開発しています。
この国では、所得に対して以下のルールで税額が計算されます:
- 所得の最初の L 円までの部分には税率 P % が適用される
- 所得の L 円を超える部分には税率 Q % が適用される
ただし、P \leq Q とは限りません。
具体的には、所得が S 円の人の税額 T は次のように計算されます:
- S \leq L のとき:T = \left\lfloor \dfrac{S \times P}{100} \right\rfloor
- S > L のとき:T = \left\lfloor \dfrac{L \times P + (S - L) \times Q}{100} \right\rfloor
ここで \lfloor x \rfloor は x を超えない最大の整数(床関数)を表します。
S > L のとき、切り捨ては L \times P の部分と (S-L) \times Q の部分それぞれに対して個別に行うのではなく、それらの合計 L \times P + (S - L) \times Q を 100 で割った結果に対して一度だけ行うことに注意してください。
例えば、L = 100、P = 10、Q = 23 のとき、所得が 150 円の人の税額は以下のように計算されます:
T = \left\lfloor \frac{100 \times 10 + (150 - 100) \times 23}{100} \right\rfloor = \left\lfloor \frac{1000 + 1150}{100} \right\rfloor = \left\lfloor \frac{2150}{100} \right\rfloor = \lfloor 21.5 \rfloor = 21 \text{ 円}
この例では、各項を個別に切り捨てた場合(\lfloor 10 \rfloor + \lfloor 11.5 \rfloor = 10 + 11 = 21 円)とたまたま同じ結果になりますが、一般には異なる場合があります。
N 人の納税者それぞれの所得額 S_i が与えられるので、各人の税額 T_i を求めてください。
制約
- 1 \leq N \leq 10^5
- 1 \leq L \leq 10^9
- 0 \leq P \leq 100
- 0 \leq Q \leq 100
- 0 \leq S_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数
入力
N L P Q S_1 S_2 \vdots S_N
- 1 行目には、納税者の人数を表す整数 N、税率が切り替わる境界の所得額(円)を表す整数 L、所得の最初の L 円までの部分に適用される税率(%)を表す整数 P、所得の L 円を超える部分に適用される税率(%)を表す整数 Q が、スペース区切りで与えられる。
- 2 行目から N + 1 行目には、各納税者の所得額が 1 行に 1 つずつ与えられる。
- 1 + i 行目には、i 番目の納税者の所得額(円)を表す整数 S_i が与えられる。
出力
T_1 T_2 \vdots T_N
- N 行で出力する。
- i 行目には、i 番目の納税者の税額 T_i を整数で出力する。
入力例 1
3 100 10 23 50 100 150
出力例 1
5 10 21
入力例 2
4 200 30 10 100 200 300 1
出力例 2
30 60 70 0
入力例 3
5 5000 15 40 0 3000 5000 8000 12345
出力例 3
0 450 750 1950 3688
入力例 4
8 1000000000 5 99 0 1 999999999 1000000000 1000000000 999999997 500000000 123456789
出力例 4
0 0 49999999 50000000 50000000 49999999 25000000 6172839
入力例 5
6 1 0 0 0 1 1000000000 0 0 1
出力例 5
0 0 0 0 0 0
Score : 233 pts
Problem Statement
Takahashi is developing a tax calculation system for a certain country.
In this country, the tax amount on income is calculated according to the following rules:
- A tax rate of P % is applied to the first L yen of income
- A tax rate of Q % is applied to the portion of income exceeding L yen
Note that P \leq Q does not necessarily hold.
Specifically, the tax amount T for a person with income S yen is calculated as follows:
- When S \leq L: T = \left\lfloor \dfrac{S \times P}{100} \right\rfloor
- When S > L: T = \left\lfloor \dfrac{L \times P + (S - L) \times Q}{100} \right\rfloor
Here, \lfloor x \rfloor denotes the largest integer not exceeding x (the floor function).
When S > L, note that the floor operation is applied only once to the result of dividing the sum L \times P + (S - L) \times Q by 100, rather than applying it individually to the L \times P part and the (S-L) \times Q part separately.
For example, when L = 100, P = 10, Q = 23, the tax amount for a person with income 150 yen is calculated as follows:
T = \left\lfloor \frac{100 \times 10 + (150 - 100) \times 23}{100} \right\rfloor = \left\lfloor \frac{1000 + 1150}{100} \right\rfloor = \left\lfloor \frac{2150}{100} \right\rfloor = \lfloor 21.5 \rfloor = 21 \text{ yen}
In this example, the result happens to be the same as when flooring each term individually (\lfloor 10 \rfloor + \lfloor 11.5 \rfloor = 10 + 11 = 21 yen), but in general they may differ.
Given the income S_i of each of N taxpayers, find each person's tax amount T_i.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq L \leq 10^9
- 0 \leq P \leq 100
- 0 \leq Q \leq 100
- 0 \leq S_i \leq 10^9 (1 \leq i \leq N)
- All inputs are integers
Input
N L P Q S_1 S_2 \vdots S_N
- The first line contains four space-separated integers: N representing the number of taxpayers, L representing the income threshold (in yen) at which the tax rate changes, P representing the tax rate (%) applied to the first L yen of income, and Q representing the tax rate (%) applied to the portion of income exceeding L yen.
- From the 2nd line to the (N + 1)-th line, each taxpayer's income is given, one per line.
- The (1 + i)-th line contains an integer S_i representing the income (in yen) of the i-th taxpayer.
Output
T_1 T_2 \vdots T_N
- Output N lines.
- The i-th line should contain the tax amount T_i of the i-th taxpayer as an integer.
Sample Input 1
3 100 10 23 50 100 150
Sample Output 1
5 10 21
Sample Input 2
4 200 30 10 100 200 300 1
Sample Output 2
30 60 70 0
Sample Input 3
5 5000 15 40 0 3000 5000 8000 12345
Sample Output 3
0 450 750 1950 3688
Sample Input 4
8 1000000000 5 99 0 1 999999999 1000000000 1000000000 999999997 500000000 123456789
Sample Output 4
0 0 49999999 50000000 50000000 49999999 25000000 6172839
Sample Input 5
6 1 0 0 0 1 1000000000 0 0 1
Sample Output 5
0 0 0 0 0 0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
高橋君は生物学の研究室で細胞培養の実験を行っています。
実験開始時点で、培養皿には S 個の細胞があります。この細胞は特殊な性質を持っており、高橋君が 1 回の「分裂促進」操作を行うと、すべての細胞が同時に分裂し、細胞の数がちょうど 2 倍になります。
高橋君が細胞の数を変化させる手段はこの「分裂促進」操作のみであり、培養皿の栄養分の都合上、この操作は 0 回以上 K 回以下しか行うことができません。
高橋君は、実験の目標として細胞の数をちょうど T 個にしたいと考えています。
細胞の数を初めの S 個からちょうど T 個にすることが可能かどうかを判定してください。可能な場合は、必要な「分裂促進」操作の最小回数を求めてください。
制約
- 1 \leq S \leq 10^{18}
- 1 \leq T \leq 10^{18}
- 0 \leq K \leq 100
- 入力はすべて整数
入力
S T K
細胞の初期個数を表す S 、目標個数を表す T 、操作可能な最大回数を表す K が、スペース区切りで 1 行に与えられる。
出力
細胞の数をちょうど T 個にすることが可能な場合は、必要な「分裂促進」操作の最小回数を 1 行で出力してください。不可能な場合は -1 を出力してください。
入力例 1
3 24 5
出力例 1
3
入力例 2
7 100 10
出力例 2
-1
入力例 3
1000000000000 8000000000000 3
出力例 3
3
Score : 300 pts
Problem Statement
Takahashi is conducting a cell cultivation experiment in a biology laboratory.
At the start of the experiment, there are S cells in the culture dish. These cells have a special property: when Takahashi performs one "mitosis promotion" operation, all cells divide simultaneously, and the number of cells exactly doubles.
The only means Takahashi has to change the number of cells is this "mitosis promotion" operation, and due to the nutrient limitations of the culture dish, this operation can only be performed between 0 and K times, inclusive.
Takahashi's experimental goal is to make the number of cells exactly T.
Determine whether it is possible to change the number of cells from the initial S to exactly T. If it is possible, find the minimum number of "mitosis promotion" operations required.
Constraints
- 1 \leq S \leq 10^{18}
- 1 \leq T \leq 10^{18}
- 0 \leq K \leq 100
- All inputs are integers
Input
S T K
S representing the initial number of cells, T representing the target number of cells, and K representing the maximum number of operations allowed are given on a single line separated by spaces.
Output
If it is possible to make the number of cells exactly T, output the minimum number of "mitosis promotion" operations required on a single line. If it is impossible, output -1.
Sample Input 1
3 24 5
Sample Output 1
3
Sample Input 2
7 100 10
Sample Output 2
-1
Sample Input 3
1000000000000 8000000000000 3
Sample Output 3
3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 366 点
問題文
高橋君は、N 個の正の整数からなる数列を持っています。この数列の i 番目(1 \leq i \leq N)の要素は A_i です。
高橋君は、この数列の連続する区間の和に興味を持っています。具体的には、整数の組 (l, r)(1 \leq l \leq r \leq N)に対して、数列の l 番目から r 番目までの要素の和
A_l + A_{l+1} + \cdots + A_r
を考えます。
整数 K が与えられるので、この和が K 以下となるような組 (l, r) の個数を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq 10^{14}
- 1 \leq A_i \leq 10^9
- 入力はすべて整数
入力
N K A_1 A_2 \ldots A_N
- 1 行目には、数列の要素数を表す整数 N と、和の上限を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、数列の各要素を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
A_l + A_{l+1} + \cdots + A_r \leq K を満たす整数の組 (l, r)(1 \leq l \leq r \leq N)の個数を 1 行で出力せよ。
入力例 1
5 5 1 2 3 4 5
出力例 1
7
入力例 2
7 10 3 1 4 1 5 9 2
出力例 2
15
入力例 3
10 1000000000000 500000000 400000000 300000000 200000000 100000000 600000000 700000000 800000000 900000000 1000000000
出力例 3
55
Score : 366 pts
Problem Statement
Takahashi has a sequence of N positive integers. The i-th element (1 \leq i \leq N) of this sequence is A_i.
Takahashi is interested in the sum of contiguous subarrays of this sequence. Specifically, for a pair of integers (l, r) (1 \leq l \leq r \leq N), he considers the sum of elements from the l-th to the r-th:
A_l + A_{l+1} + \cdots + A_r
Given an integer K, find the number of pairs (l, r) such that this sum is at most K.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq 10^{14}
- 1 \leq A_i \leq 10^9
- 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 elements in the sequence and an integer K representing the upper bound of the sum, separated by a space.
- The second line contains integers A_1, A_2, \ldots, A_N representing each element of the sequence, separated by spaces.
Output
Print on one line the number of pairs of integers (l, r) (1 \leq l \leq r \leq N) satisfying A_l + A_{l+1} + \cdots + A_r \leq K.
Sample Input 1
5 5 1 2 3 4 5
Sample Output 1
7
Sample Input 2
7 10 3 1 4 1 5 9 2
Sample Output 2
15
Sample Input 3
10 1000000000000 500000000 400000000 300000000 200000000 100000000 600000000 700000000 800000000 900000000 1000000000
Sample Output 3
55
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
高橋君は旅行先でお土産を選ぼうとしています。
お土産売り場には N 種類のお菓子と M 種類の飲み物が売られています。i 番目のお菓子の美味しさは A_i 、j 番目の飲み物の美味しさは B_j です。
i 番目のお菓子と j 番目の飲み物を組み合わせたときの満足度を、美味しさの積 A_i \times B_j で定めます。
お菓子と飲み物の組み合わせは全部で N \times M 通りあります。これら N \times M 通りの組み合わせの満足度を大きい順に並べたとき、先頭から K 個の満足度の合計値を求めてください。
ただし、組み合わせ (i_1, j_1) と (i_2, j_2) は、i_1 \neq i_2 または j_1 \neq j_2 であれば、たとえ満足度の値が等しくても異なる組み合わせとみなします。すなわち、上位 K 個を選ぶ際にも合計を求める際にも、それぞれ別の組み合わせとして 1 個ずつ数えます。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq K \leq \min(N \times M,\, 2 \times 10^5)
- 1 \leq A_i \leq 10^5 (1 \leq i \leq N)
- 1 \leq B_j \leq 10^5 (1 \leq j \leq M)
- 入力はすべて整数である。
入力
N M K A_1 A_2 \dots A_N B_1 B_2 \dots B_M
- 1 行目には、お菓子の種類数 N 、飲み物の種類数 M 、選ぶ組み合わせの個数 K が、空白区切りで与えられる。
- 2 行目には、各お菓子の美味しさ A_1, A_2, \dots, A_N が、空白区切りで与えられる。
- 3 行目には、各飲み物の美味しさ B_1, B_2, \dots, B_M が、空白区切りで与えられる。
出力
N \times M 通りの組み合わせの満足度のうち、大きい方から K 個の合計値を整数として 1 行で出力せよ。末尾に改行を含めること。
入力例 1
2 3 3 3 1 2 4 1
出力例 1
22
入力例 2
4 4 5 5 3 7 1 4 6 2 8
出力例 2
196
入力例 3
5 6 8 10 20 30 40 50 3 6 9 12 15 18
出力例 3
5040
Score : 400 pts
Problem Statement
Takahashi is choosing souvenirs at his travel destination.
The souvenir shop sells N types of sweets and M types of drinks. The deliciousness of the i-th sweet is A_i, and the deliciousness of the j-th drink is B_j.
The satisfaction of combining the i-th sweet and the j-th drink is defined as the product of their deliciousness values, A_i \times B_j.
There are N \times M possible combinations of sweets and drinks in total. When these N \times M combinations are sorted in descending order of satisfaction, find the sum of the first K satisfaction values.
Note that combinations (i_1, j_1) and (i_2, j_2) are considered different as long as i_1 \neq i_2 or j_1 \neq j_2, even if their satisfaction values are equal. That is, when selecting the top K and computing the sum, each combination is counted individually as a separate one.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq K \leq \min(N \times M,\, 2 \times 10^5)
- 1 \leq A_i \leq 10^5 (1 \leq i \leq N)
- 1 \leq B_j \leq 10^5 (1 \leq j \leq M)
- All input values are integers.
Input
N M K A_1 A_2 \dots A_N B_1 B_2 \dots B_M
- The first line contains the number of sweet types N, the number of drink types M, and the number of combinations to select K, separated by spaces.
- The second line contains the deliciousness of each sweet A_1, A_2, \dots, A_N, separated by spaces.
- The third line contains the deliciousness of each drink B_1, B_2, \dots, B_M, separated by spaces.
Output
Output the sum of the top K satisfaction values (in descending order) among all N \times M combinations, as an integer on a single line. Include a newline at the end.
Sample Input 1
2 3 3 3 1 2 4 1
Sample Output 1
22
Sample Input 2
4 4 5 5 3 7 1 4 6 2 8
Sample Output 2
196
Sample Input 3
5 6 8 10 20 30 40 50 3 6 9 12 15 18
Sample Output 3
5040
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 433 点
問題文
高橋君は配達員として、N 軒の家に荷物を届けることになりました。家には 1, 2, \ldots, N と番号が付けられており、家 i の標高は V_i です。標高は家ごとに異なるとは限らず、同じ値をとることもあります。
高橋君は最初、家 1 にいます。家 1 への配達はすでに完了しており、家 1 は訪問済みの状態です。高橋君はこれから、残りの家 2, 3, \ldots, N のすべてに荷物を届ける必要があります。
配達は以下のように行います。高橋君は N - 1 回の移動を行い、各移動では、現在いる家からまだ訪問していない家をちょうど 1 軒選んで移動し、その家を訪問済みとします。移動先は隣の家である必要はなく、まだ訪問していない家であればどの家でも直接移動できます。すべての家をちょうど 1 回ずつ訪問したら配達は終了です。最後にどの家にいても構いません(家 1 に戻る必要はありません)。
家 i から家 j へ直接移動するときの移動コストは、途中にどのような家があるかによらず、次の式で定まります:
|V_i - V_j| \times |i - j|
すなわち、標高の差の絶対値と家の番号の差の絶対値の積がコストとなります。
N - 1 回の移動コストの合計を最小化してください。
制約
- 1 \leq N \leq 20
- 0 \leq V_i \leq 10^9(1 \leq i \leq N)
- 入力はすべて整数である。
入力
N V_1 V_2 \ldots V_N
- 1 行目には、家の軒数を表す整数 N が与えられる。
- 2 行目には、各家の標高を表す N 個の整数 V_1, V_2, \ldots, V_N がスペース区切りで与えられる。
出力
すべての家をちょうど 1 回ずつ訪問するための移動コストの合計の最小値を 1 行で出力せよ。
入力例 1
3 10 20 40
出力例 1
30
入力例 2
4 5 3 8 1
出力例 2
13
入力例 3
8 100 250 120 400 50 300 180 90
出力例 3
950
入力例 4
15 1000000000 0 500000000 250000000 750000000 125000000 875000000 62500000 937500000 31250000 968750000 15625000 984375000 7812500 992187500
出力例 4
1921875000
入力例 5
1 0
出力例 5
0
Score : 433 pts
Problem Statement
Takahashi is a delivery person who needs to deliver packages to N houses. The houses are numbered 1, 2, \ldots, N, and the elevation of house i is V_i. Elevations are not necessarily distinct; different houses may have the same elevation.
Takahashi starts at house 1. The delivery to house 1 is already complete, and house 1 is already marked as visited. Takahashi must now deliver packages to all remaining houses 2, 3, \ldots, N.
Deliveries are performed as follows. Takahashi makes N - 1 moves. In each move, he selects exactly one unvisited house from his current location, moves to it, and marks it as visited. The destination does not need to be an adjacent house; he can move directly to any unvisited house. The delivery is complete once all houses have been visited exactly once. It does not matter which house he ends at (he does not need to return to house 1).
The cost of moving directly from house i to house j is determined by the following formula, regardless of what houses lie in between:
|V_i - V_j| \times |i - j|
In other words, the cost is the product of the absolute difference in elevations and the absolute difference in house numbers.
Minimize the total cost of the N - 1 moves.
Constraints
- 1 \leq N \leq 20
- 0 \leq V_i \leq 10^9 (1 \leq i \leq N)
- All input values are integers.
Input
N V_1 V_2 \ldots V_N
- The first line contains an integer N, representing the number of houses.
- The second line contains N integers V_1, V_2, \ldots, V_N separated by spaces, representing the elevation of each house.
Output
Print on a single line the minimum total movement cost required to visit all houses exactly once.
Sample Input 1
3 10 20 40
Sample Output 1
30
Sample Input 2
4 5 3 8 1
Sample Output 2
13
Sample Input 3
8 100 250 120 400 50 300 180 90
Sample Output 3
950
Sample Input 4
15 1000000000 0 500000000 250000000 750000000 125000000 875000000 62500000 937500000 31250000 968750000 15625000 984375000 7812500 992187500
Sample Output 4
1921875000
Sample Input 5
1 0
Sample Output 5
0