実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 233 点
問題文
高橋君はフリーランスのプログラマーとして働いています。現在、 N 件の案件を抱えており、それぞれの案件には番号 1 から N が付けられています。
案件 i は納品まで D_i 日かかる予定で、納品が完了すると V_i 円の報酬を受け取ることができます。
高橋君はエージェント会社を通じて案件を獲得しています。エージェント会社との契約により、受け取った報酬の合計に対して、手数料として P パーセントをエージェント会社に支払わなければなりません。
高橋君は今後 M 日間の収支を計算しようとしています。 M 日以内に納品が完了する案件の報酬の合計から、エージェント会社への手数料を差し引いた金額を求めてください。
ただし、答えは小数点以下を切り捨てた整数で出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 10^9
- 0 \leq P \leq 100
- 1 \leq D_i \leq 10^9
- 1 \leq V_i \leq 10^6
- 入力はすべて整数
入力
N M P D_1 V_1 D_2 V_2 : D_N V_N
- 1 行目には、案件の件数を表す N 、計画期間の日数を表す M 、手数料の割合(パーセント)を表す P が、スペース区切りで与えられる。
- 2 行目から N + 1 行目では、各案件の情報が N 行で与えられる。
- 1 + i 行目では、案件 i の納品までの日数 D_i と、報酬 V_i が、スペース区切りで与えられる。
出力
M 日以内に納品が完了する案件の報酬の合計から、手数料を差し引いた金額を、小数点以下を切り捨てた整数として 1 行で出力してください。
入力例 1
4 5 10 3 1000 5 2000 6 3000 1 500
出力例 1
3150
入力例 2
3 2 20 3 100 5 200 10 300
出力例 2
0
入力例 3
10 30 15 10 12000 30 25000 31 40000 5 8000 25 15000 60 50000 1 3000 29 22000 45 18000 30 7000
出力例 3
78200
入力例 4
30 500 37 120 450000 800 320000 499 100000 500 999999 501 250000 30 75000 365 640000 1000 120000 250 333333 490 222222 10 1000000 700 111111 450 555555 600 444444 1 123456 499 654321 502 98765 300 777777 200 888888 550 99999 400 135790 480 246800 90 112233 510 445566 20 778899 470 314159 900 271828 350 161803 500 424242 750 202020
出力例 4
5666520
入力例 5
1 1000000000 100 1000000000 1000000
出力例 5
0
Score : 233 pts
Problem Statement
Takahashi works as a freelance programmer. He currently has N projects, each numbered from 1 to N.
Project i is expected to take D_i days until delivery, and upon completion of delivery, he will receive a reward of V_i yen.
Takahashi acquires projects through an agent company. Due to his contract with the agent company, he must pay P percent of the total received rewards to the agent company as a commission fee.
Takahashi is trying to calculate his income and expenses for the next M days. Find the amount obtained by subtracting the agent company's commission fee from the total rewards of projects whose delivery is completed within M days.
Note that the answer should be output as an integer with the decimal part truncated (rounded down).
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 10^9
- 0 \leq P \leq 100
- 1 \leq D_i \leq 10^9
- 1 \leq V_i \leq 10^6
- All inputs are integers
Input
N M P D_1 V_1 D_2 V_2 : D_N V_N
- The first line contains N representing the number of projects, M representing the number of days in the planning period, and P representing the commission rate (in percent), separated by spaces.
- From the 2nd line to the (N + 1)-th line, information about each project is given over N lines.
- The (1 + i)-th line contains D_i, the number of days until delivery of project i, and V_i, the reward, separated by spaces.
Output
Output in a single line the amount obtained by subtracting the commission fee from the total rewards of projects whose delivery is completed within M days, as an integer with the decimal part truncated (rounded down).
Sample Input 1
4 5 10 3 1000 5 2000 6 3000 1 500
Sample Output 1
3150
Sample Input 2
3 2 20 3 100 5 200 10 300
Sample Output 2
0
Sample Input 3
10 30 15 10 12000 30 25000 31 40000 5 8000 25 15000 60 50000 1 3000 29 22000 45 18000 30 7000
Sample Output 3
78200
Sample Input 4
30 500 37 120 450000 800 320000 499 100000 500 999999 501 250000 30 75000 365 640000 1000 120000 250 333333 490 222222 10 1000000 700 111111 450 555555 600 444444 1 123456 499 654321 502 98765 300 777777 200 888888 550 99999 400 135790 480 246800 90 112233 510 445566 20 778899 470 314159 900 271828 350 161803 500 424242 750 202020
Sample Output 4
5666520
Sample Input 5
1 1000000000 100 1000000000 1000000
Sample Output 5
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
高橋君の学校では文化祭の募金活動を行っており、 N 個のチームがそれぞれ募金を集めた。チーム i が集めた金額は A_i 円である。
学校の規定では、全チームの募金総額の半分以上を集めたチームの集まりを「表彰対象」とすることになっている。高橋君は、できるだけ少ないチーム数で表彰対象の条件を満たしたいと考えている。
具体的には、 N 個のチームからいくつかのチームを選び、選んだチームの募金額の合計が全チームの募金総額の半分以上(すなわち、総額を T としたとき \lceil T / 2 \rceil 以上)となるようにしたい。このような選び方のうち、選ぶチーム数が最小となるものを求め、その最小のチーム数を出力してください。
制約
- 1 \leq N \leq 10^6
- 1 \leq A_i \leq 10^9
- 入力はすべて整数である。
入力
N A_1 A_2 \ldots A_N
- 1 行目には、チームの数を表す整数 N が与えられる。
- 2 行目には、各チームが集めた募金額を表す N 個の整数 A_1, A_2, \ldots, A_N がスペース区切りで与えられる。
出力
表彰対象の条件を満たすために必要な最小のチーム数を 1 行で出力してください。
入力例 1
5 10 20 30 40 50
出力例 1
2
入力例 2
4 5 5 5 5
出力例 2
2
入力例 3
12 8 15 3 22 7 14 30 6 11 25 9 18
出力例 3
4
入力例 4
30 120 45 300 75 210 90 15 480 60 135 255 195 30 405 150 225 345 105 270 390 165 510 240 315 435 180 360 285 555 600
出力例 4
9
入力例 5
1 1000000000
出力例 5
1
Score : 300 pts
Problem Statement
At Takahashi's school, a fundraising activity was held during the school festival, and N teams collected donations. Team i collected A_i yen.
According to the school regulations, a group of teams is eligible for an award if the sum of their donations is at least half of the total amount collected by all teams. Takahashi wants to satisfy this condition with as few teams as possible.
Specifically, he wants to select a subset of the N teams such that the sum of the donations of the selected teams is at least half of the total amount collected by all teams (i.e., at least \lceil T / 2 \rceil, where T is the total amount). Find the minimum number of teams that need to be selected, and print this minimum count.
Constraints
- 1 \leq N \leq 10^6
- 1 \leq A_i \leq 10^9
- All input values are integers.
Input
N A_1 A_2 \ldots A_N
- The first line contains an integer N, representing the number of teams.
- The second line contains N space-separated integers A_1, A_2, \ldots, A_N, representing the amount of donations collected by each team.
Output
Print the minimum number of teams required to satisfy the award condition in a single line.
Sample Input 1
5 10 20 30 40 50
Sample Output 1
2
Sample Input 2
4 5 5 5 5
Sample Output 2
2
Sample Input 3
12 8 15 3 22 7 14 30 6 11 25 9 18
Sample Output 3
4
Sample Input 4
30 120 45 300 75 210 90 15 480 60 135 255 195 30 405 150 225 345 105 270 390 165 510 240 315 435 180 360 285 555 600
Sample Output 4
9
Sample Input 5
1 1000000000
Sample Output 5
1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 366 点
問題文
高橋君は、ある感染症の拡大状況を調査する疫学研究者です。
ある地域には N 人の住民がおり、それぞれ 1 から N までの番号が付けられています。住民間には M 組の接触関係が記録されており、接触関係は双方向です。つまり、住民 A と住民 B が接触していれば、A から B へも B から A へも感染の可能性があります。
高橋君は、最初の感染者である住民 S から、接触関係を通じて感染が広がる可能性のある範囲を調べたいと考えています。
住民 S から住民 T への最短接触回数を、住民 S から住民 T まで接触関係をたどって到達するために経由する接触関係の最小個数として定義します。住民 S 自身への最短接触回数は 0 です。接触関係をどのようにたどっても住民 S から住民 T に到達できない場合、住民 T への最短接触回数は定義されないものとします。
高橋君のために、住民 S からの最短接触回数が定義され、かつその値が K 以下である住民の人数を求めてください。
例えば、K = 0 の場合は住民 S 自身のみが対象となり、答えは 1 です。K = 1 の場合は住民 S 自身と S に直接接触している住民が対象となります。K = 2 の場合は、さらにその接触者の接触者も対象に含まれます。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq \min(2 \times 10^5, \frac{N(N-1)}{2})
- 1 \leq S \leq N
- 0 \leq K \leq N
- 1 \leq U_i < V_i \leq N (1 \leq i \leq M)
- (U_i, V_i) \neq (U_j, V_j) (i \neq j)(同じ接触関係は複数回記録されない)
- 入力はすべて整数
入力
N M S K U_1 V_1 U_2 V_2 \vdots U_M V_M
- 1 行目には、住民の人数を表す N 、接触関係の数を表す M 、最初の感染者の番号を表す S 、最短接触回数の上限を表す K が、スペース区切りで与えられる。
- 続く M 行で、接触関係が与えられる(M = 0 の場合、この部分は存在しない)。
- そのうち i 行目 (1 \leq i \leq M) では、i 番目の接触関係における 2 人の住民の番号 U_i と V_i がスペース区切りで与えられる。これは住民 U_i と住民 V_i が接触していることを表す。
出力
住民 S からの最短接触回数が K 以下である住民の人数を 1 行で出力せよ。
入力例 1
5 4 1 2 1 2 2 3 3 4 4 5
出力例 1
3
入力例 2
7 8 3 1 1 2 1 3 2 3 3 4 3 5 4 6 5 6 6 7
出力例 2
5
入力例 3
10 12 1 3 1 2 1 3 2 4 2 5 3 6 4 7 5 7 6 8 7 9 8 9 8 10 9 10
出力例 3
8
Score : 366 pts
Problem Statement
Takahashi is an epidemiological researcher investigating the spread of an infectious disease.
A certain region has N residents, each numbered from 1 to N. There are M recorded contact relationships between residents, and these contact relationships are bidirectional. That is, if resident A and resident B are in contact, infection can potentially spread from A to B and from B to A.
Takahashi wants to investigate the range to which infection can potentially spread from resident S, the initial infected person, through contact relationships.
The shortest contact count from resident S to resident T is defined as the minimum number of contact relationships traversed to reach resident T from resident S by following contact relationships. The shortest contact count from resident S to themselves is 0. If resident T cannot be reached from resident S by following any sequence of contact relationships, the shortest contact count to resident T is considered undefined.
For Takahashi, find the number of residents for whom the shortest contact count from resident S is defined and is at most K.
For example, if K = 0, only resident S themselves is counted, so the answer is 1. If K = 1, resident S and all residents in direct contact with S are counted. If K = 2, the contacts of those contacts are also included.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq M \leq \min(2 \times 10^5, \frac{N(N-1)}{2})
- 1 \leq S \leq N
- 0 \leq K \leq N
- 1 \leq U_i < V_i \leq N (1 \leq i \leq M)
- (U_i, V_i) \neq (U_j, V_j) (i \neq j) (the same contact relationship is not recorded more than once)
- All inputs are integers
Input
N M S K U_1 V_1 U_2 V_2 \vdots U_M V_M
- The first line contains N representing the number of residents, M representing the number of contact relationships, S representing the number of the initial infected person, and K representing the upper limit of the shortest contact count, separated by spaces.
- The following M lines give the contact relationships (if M = 0, this part does not exist).
- The i-th of these lines (1 \leq i \leq M) contains the numbers U_i and V_i of the two residents in the i-th contact relationship, separated by a space. This indicates that resident U_i and resident V_i are in contact.
Output
Output in one line the number of residents whose shortest contact count from resident S is at most K.
Sample Input 1
5 4 1 2 1 2 2 3 3 4 4 5
Sample Output 1
3
Sample Input 2
7 8 3 1 1 2 1 3 2 3 3 4 3 5 4 6 5 6 6 7
Sample Output 2
5
Sample Input 3
10 12 1 3 1 2 1 3 2 4 2 5 3 6 4 7 5 7 6 8 7 9 8 9 8 10 9 10
Sample Output 3
8
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
整数座標がついたマスが一列に無限に並んだ廊下があります。この廊下には高橋君と青木君の2人だけがおり、それぞれ異なるマスに立っています。はじめ、高橋君はマス A に、青木君はマス B にいます。
最終的に、高橋君をマス C に、青木君をマス D に移動させたいです。
あなたは次の操作を好きな回数(0回でもよい)行えます。
- 任意の整数 x を 1 つ選び、マス x とマス x + 1 にいる人を交換する。具体的には、マス x とマス x+1 の両方に人がいる場合は2人の位置が交換され、一方のマスにだけ人がいる場合はその人がもう一方のマスへ移動し、どちらのマスにも人がいない場合は何も起こらない。
この操作は隣接する2マスの間での交換であるため、1つのマスに2人が同時に存在することは決して起こりません。
与えられる入力に対して、目標の配置は必ず達成可能であることが証明できます。目標の配置を達成するために必要な最小の操作回数を求めてください。
制約
- -10^{18} \leq A, B, C, D \leq 10^{18}
- A \neq B
- C \neq D
- 入力はすべて整数である
- この制約下で、答えは符号付き 64 bit 整数型に収まる
入力
A B C D
1 行目には、高橋君の初期位置を表す整数 A 、青木君の初期位置を表す整数 B 、高橋君の目標位置を表す整数 C 、青木君の目標位置を表す整数 D が、スペース区切りで与えられる。
出力
目標の配置を達成するために必要な最小の操作回数を整数で出力せよ。
入力例 1
0 2 1 3
出力例 1
2
入力例 2
0 1 1 0
出力例 2
1
入力例 3
-10 20 15 -5
出力例 3
49
入力例 4
-1000000000 2000000000 3000000000 -4000000000
出力例 4
9999999999
入力例 5
-1000000000000000000 1000000000000000000 999999999999999999 -999999999999999999
出力例 5
3999999999999999997
Score : 400 pts
Problem Statement
There is a corridor consisting of an infinite row of cells labeled with integer coordinates. Only two people are in this corridor: Takahashi and Aoki, each standing on a different cell. Initially, Takahashi is on cell A and Aoki is on cell B.
The goal is to move Takahashi to cell C and Aoki to cell D.
You can perform the following operation any number of times (possibly zero):
- Choose any integer x, and swap the people on cell x and cell x + 1. Specifically, if both cells x and x+1 have a person, the two people exchange positions; if only one of the cells has a person, that person moves to the other cell; if neither cell has a person, nothing happens.
Since this operation is a swap between two adjacent cells, it is never possible for two people to occupy the same cell simultaneously.
It can be proven that the goal configuration is always achievable for the given inputs. Find the minimum number of operations required to achieve the goal configuration.
Constraints
- -10^{18} \leq A, B, C, D \leq 10^{18}
- A \neq B
- C \neq D
- All inputs are integers
- Under these constraints, the answer fits in a signed 64-bit integer type
Input
A B C D
The first line contains integers A, B, C, D separated by spaces, representing Takahashi's initial position, Aoki's initial position, Takahashi's goal position, and Aoki's goal position, respectively.
Output
Print the minimum number of operations required to achieve the goal configuration as an integer.
Sample Input 1
0 2 1 3
Sample Output 1
2
Sample Input 2
0 1 1 0
Sample Output 2
1
Sample Input 3
-10 20 15 -5
Sample Output 3
49
Sample Input 4
-1000000000 2000000000 3000000000 -4000000000
Sample Output 4
9999999999
Sample Input 5
-1000000000000000000 1000000000000000000 999999999999999999 -999999999999999999
Sample Output 5
3999999999999999997
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 433 点
問題文
高橋君は N 個の区画からなる土地を管理しています。i 番目の区画の地面の高さは H_i です。
高橋君は、この土地を整地するために次の操作を繰り返し行えます。
操作: 1 \le l \le r \le N を満たす整数の組 (l, r) を一つ選び、l 番目から r 番目までの各区画の高さをそれぞれ 1 だけ減らす。
この操作は 0 回以上何度でも行うことができ、毎回選ぶ (l, r) は自由に決めてよいです(同じ組を複数回選ぶこともできます)。なお、この操作では高さを減らすことのみが可能であり、高さを増やすことはできません。
また、操作の過程および最終状態を含むすべての時点において、すべての区画の高さは 0 以上でなければなりません。
高橋君の目標は、すべての操作が完了した後の土地の高さの列を「山型」にすることです。操作後の i 番目の区画の高さを H'_i とするとき、列 H'_1, H'_2, \ldots, H'_N が山型であるとは、ある添字 k( 1 \le k \le N )が存在して、
H'_1 \le H'_2 \le \cdots \le H'_k \ge H'_{k+1} \ge \cdots \ge H'_N
を満たすことをいいます。すなわち、ある k が存在して、H'_1 から H'_k までが広義単調非減少であり、かつ H'_k から H'_N までが広義単調非増加であることを意味します。特に、広義単調非減少な列(k = N の場合)や広義単調非増加な列(k = 1 の場合)、すべての高さが等しい列も山型に含まれます。また、N = 1 のときは常に山型です。
高橋君は操作回数を最小にしつつ土地を山型にしたいと考えています。必要な操作の最小回数を求めてください。
制約
- 1 \leq N \leq 10^6
- 0 \leq H_i \leq 10^9
- 入力はすべて整数である。
入力
N H_1 H_2 \cdots H_N
- 1 行目には、区画の個数を表す整数 N が与えられる。
- 2 行目には、各区画の高さを表す N 個の整数 H_1, H_2, \ldots, H_N がスペース区切りで与えられる。
出力
土地を山型にするために必要な操作の最小回数を 1 行で出力せよ。
入力例 1
5 2 1 3 2 1
出力例 1
1
入力例 2
6 0 2 2 5 3 1
出力例 2
0
入力例 3
15 4 8 1 7 7 3 10 6 2 9 5 5 1 4 0
出力例 3
21
入力例 4
50 12 0 15 15 3 22 7 30 18 5 5 40 1 26 26 9 33 14 14 2 45 11 29 6 6 38 20 4 31 31 8 17 23 23 10 36 13 27 0 19 19 34 16 16 28 21 21 35 24 12
出力例 4
343
入力例 5
1 1000000000
出力例 5
0
Score : 433 pts
Problem Statement
Takahashi manages a piece of land consisting of N plots. The height of the i-th plot is H_i.
To level this land, Takahashi can repeatedly perform the following operation:
Operation: Choose a pair of integers (l, r) satisfying 1 \le l \le r \le N, and decrease the height of each plot from the l-th to the r-th plot by 1.
This operation can be performed zero or more times, and he can freely choose (l, r) each time (the same pair can be chosen multiple times). Note that this operation can only decrease heights; it cannot increase them.
Furthermore, at all points in time, including during the process and in the final state, the height of every plot must be at least 0.
Takahashi's goal is to make the sequence of heights "mountain-shaped" after all operations are completed. Letting H'_i be the height of the i-th plot after the operations, the sequence H'_1, H'_2, \ldots, H'_N is said to be mountain-shaped if there exists an index k (1 \le k \le N) such that:
H'_1 \le H'_2 \le \cdots \le H'_k \ge H'_{k+1} \ge \cdots \ge H'_N
That is, there exists some k such that the sequence from H'_1 to H'_k is monotonically non-decreasing, and the sequence from H'_k to H'_N is monotonically non-increasing. In particular, a monotonically non-decreasing sequence (the case where k = N), a monotonically non-increasing sequence (the case where k = 1), and a sequence where all heights are equal are also considered mountain-shaped. Additionally, when N = 1, the sequence is always mountain-shaped.
Takahashi wants to make the land mountain-shaped while minimizing the number of operations. Find the minimum number of operations required.
Constraints
- 1 \leq N \leq 10^6
- 0 \leq H_i \leq 10^9
- All input values are integers.
Input
N H_1 H_2 \cdots H_N
- The first line contains an integer N, representing the number of plots.
- The second line contains N space-separated integers H_1, H_2, \ldots, H_N, representing the height of each plot.
Output
Print the minimum number of operations required to make the land mountain-shaped in a single line.
Sample Input 1
5 2 1 3 2 1
Sample Output 1
1
Sample Input 2
6 0 2 2 5 3 1
Sample Output 2
0
Sample Input 3
15 4 8 1 7 7 3 10 6 2 9 5 5 1 4 0
Sample Output 3
21
Sample Input 4
50 12 0 15 15 3 22 7 30 18 5 5 40 1 26 26 9 33 14 14 2 45 11 29 6 6 38 20 4 31 31 8 17 23 23 10 36 13 27 0 19 19 34 16 16 28 21 21 35 24 12
Sample Output 4
343
Sample Input 5
1 1000000000
Sample Output 5
0