実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
入学試験の受験者が N 人います。
試験の結果、 i 番の受験生は数学で A_i 点、英語で B_i 点を取りました。
試験の合格者は次のように決められます。
- 数学の点が高い方から X 人を合格とする。
- 次に、この時点でまだ合格となっていない受験者のうち、英語の点が高い方から Y 人を合格とする。
- 次に、この時点でまだ合格となっていない受験者のうち、数学と英語の合計点が高い方から Z 人を合格とする。
- ここまでで合格となっていない受験者は、不合格とする。
ただし、 1. から 3. までのどの段階についても、同点であった場合は受験生の番号の小さい方を優先します。入出力例も参照してください。
以上の手順で合格者を決める時、合格となった受験生の番号を小さい方から順に改行区切りで出力してください。
制約
- 入力は全て整数
- 1 \le N \le 1000
- 0 \le X,Y,Z \le N
- 1 \le X+Y+Z \le N
- 0 \le A_i,B_i \le 100
入力
入力は以下の形式で標準入力から与えられる。
N X Y Z A_1 A_2 \dots A_N B_1 B_2 \dots B_N
出力
合格となった受験生の番号を小さい方から順に改行区切りで出力せよ。
入力例 1
6 1 0 2 80 60 80 60 70 70 40 20 50 90 90 80
出力例 1
1 4 5
- まず、数学の点が高い方から 1 人が合格となります。
- 数学の最高点は 80 点で 1 番の受験生と 3 番の受験生が並んでいますが、受験生の番号が小さい方が優先され 1 番の受験生が合格となります。
- 次に、まだ合格となっていない受験者のうち、英語の点が高い方から 0 人が合格となります。
- 明らかに、ここで合格者が増えることはありません。
- 次に、まだ合格となっていない受験者のうち、数学と英語の合計点が高い方から 2 人が合格となります。
- まず、まだ合格となっていない受験者の中で、合計点が 160 点と最も高い 5 番の受験生が合格となります。
- 次に、まだ合格となっていない受験者の中で、合計点が 150 点の 4 番の受験生と 6 番の受験生が並んでいます。受験生の番号の小さい方が優先され、 4 番の受験生が合格となります。
以上より、合格となる受験生の番号は 1,4,5 なので、小さい方から出力してください。
入力例 2
5 2 1 2 0 100 0 100 0 0 0 100 100 0
出力例 2
1 2 3 4 5
全員が合格となることもあります。
入力例 3
15 4 3 2 30 65 20 95 100 45 70 85 20 35 95 50 40 15 85 0 25 45 35 65 70 80 90 40 55 20 20 45 75 100
出力例 3
2 4 5 6 7 8 11 14 15
Score : 200 points
Problem Statement
N examinees took an entrance exam.
The examinee numbered i scored A_i points in math and B_i points in English.
The admissions are determined as follows.
- X examinees with the highest math scores are admitted.
- Then, among the examinees who are not admitted yet, Y examinees with the highest English scores are admitted.
- Then, among the examinees who are not admitted yet, Z examinees with the highest total scores in math and English are admitted.
- Those examinees who are not admitted yet are rejected.
Here, in each of the steps 1. to 3., ties are broken by examinees' numbers: an examinee with the smaller examinee's number is prioritized. See also Sample Input and Output.
Print the examinees' numbers of the admitted examinees determined by the steps above in ascending order, separated by newlines.
Constraints
- All values in input are integers.
- 1 \le N \le 1000
- 0 \le X,Y,Z \le N
- 1 \le X+Y+Z \le N
- 0 \le A_i,B_i \le 100
Input
Input is given from Standard Input in the following format:
N X Y Z A_1 A_2 \dots A_N B_1 B_2 \dots B_N
Output
Print the examinees' number of the admitted examinees in ascending order, separated by newlines.
Sample Input 1
6 1 0 2 80 60 80 60 70 70 40 20 50 90 90 80
Sample Output 1
1 4 5
- First, 1 examinee with the highest math score is admitted.
- Examinee 1 is tied with Examinee 3, scoring the highest 80 points in math, and the tie is broken by the examinees' numbers, so Examinee 1 is admitted.
- Then, among the examinees who are not admitted yet, 0 examinees with the highest English scores are admitted.
- Obviously, it does not affect the admissions.
- Then, among the examinees who are not admitted yet, 2 examinees with the highest total scores in math and English are admitted.
- First, among the examinees who are not admitted yet, Examinee 5 is admitted, scoring the highest total score of 160 points.
- Next, among the examinees who are not admitted yet, Examinee 4 is tied with Examinee 6, scoring a total score of 150 points. The tie is broken by the examinees' numbers, and Examinee 4 is admitted.
Therefore, the examinees' numbers of the admitted examinees are 1, 4, and 5. Print them in ascending order.
Sample Input 2
5 2 1 2 0 100 0 100 0 0 0 100 100 0
Sample Output 2
1 2 3 4 5
All examinees may be admitted.
Sample Input 3
15 4 3 2 30 65 20 95 100 45 70 85 20 35 95 50 40 15 85 0 25 45 35 65 70 80 90 40 55 20 20 45 75 100
Sample Output 3
2 4 5 6 7 8 11 14 15
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
非負整数 A,B,C,D,E,F があり、A\times B\times C\geq D\times E\times F をみたしています。
(A\times B\times C)-(D\times E\times F) の値を 998244353 で割った余りを求めてください。
制約
- 0\leq A,B,C,D,E,F\leq 10^{18}
- A\times B\times C\geq D\times E\times F
- A,B,C,D,E,F は整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D E F
出力
(A\times B\times C)-(D\times E\times F) を 998244353 で割った余りを整数で出力せよ。
入力例 1
2 3 5 1 2 4
出力例 1
22
A\times B\times C=2\times 3\times 5=30, D\times E\times F=1\times 2\times 4=8 より、
(A\times B\times C)-(D\times E\times F)=22 であり、これを 998244353 で割った余りである 22 を出力します。
入力例 2
1 1 1000000000 0 0 0
出力例 2
1755647
A\times B\times C=1000000000, D\times E\times F=0 より、
(A\times B\times C)-(D\times E\times F)=1000000000 であり、これを 998244353 で割った余りである 1755647 を出力します。
入力例 3
1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000
出力例 3
0
(A\times B\times C)-(D\times E\times F)=0 であり、これを 998244353 で割った余りである 0 を出力します。
Score : 200 points
Problem Statement
There are non-negative integers A, B, C, D, E, and F, which satisfy A\times B\times C\geq D\times E\times F.
Find the remainder when (A\times B\times C)-(D\times E\times F) is divided by 998244353.
Constraints
- 0\leq A,B,C,D,E,F\leq 10^{18}
- A\times B\times C\geq D\times E\times F
- A, B, C, D, E, and F are integers.
Input
The input is given from Standard Input in the following format:
A B C D E F
Output
Print the remainder when (A\times B\times C)-(D\times E\times F) is divided by 998244353, as an integer.
Sample Input 1
2 3 5 1 2 4
Sample Output 1
22
Since A\times B\times C=2\times 3\times 5=30 and D\times E\times F=1\times 2\times 4=8,
we have (A\times B\times C)-(D\times E\times F)=22. Divide this by 998244353 and print the remainder, which is 22.
Sample Input 2
1 1 1000000000 0 0 0
Sample Output 2
1755647
Since A\times B\times C=1000000000 and D\times E\times F=0,
we have (A\times B\times C)-(D\times E\times F)=1000000000. Divide this by 998244353 and print the remainder, which is 1755647.
Sample Input 3
1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000
Sample Output 3
0
We have (A\times B\times C)-(D\times E\times F)=0. Divide this by 998244353 and print the remainder, which is 0.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
空の箱があります。
髙橋君は以下の 2 種類の魔法を好きな順番で好きな回数使えます。
- 魔法 A :箱の中にボールを 1 つ増やす
- 魔法 B :箱の中のボールの数を 2 倍にする
合計 \mathbf{120} 回以内の魔法で、箱の中のボールの数をちょうど N 個にする方法を 1 つ教えてください。
なお、与えられた制約のもとで条件を満たす方法が必ず存在することが示せます。
魔法以外の方法でボールの数を変化させることはできません。
制約
- 1 \leq N \leq 10^{18}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
A , B のみからなる文字列 S を出力せよ。
S の i 文字目が A ならば、髙橋君が i 回目に使う魔法が魔法 A であることを表し、B ならば魔法 B であることを表す。
S の長さは \mathbf{120} 以下でなければならない。
入力例 1
5
出力例 1
AABA
ボールの数は、0 \xrightarrow{A} 1\xrightarrow{A} 2 \xrightarrow{B}4\xrightarrow{A} 5 と変化します。
AAAAA などの答えも正解になります。
入力例 2
14
出力例 2
BBABBAAAB
ボールの数は、0 \xrightarrow{B} 0 \xrightarrow{B} 0 \xrightarrow{A}1 \xrightarrow{B} 2 \xrightarrow{B} 4 \xrightarrow{A}5 \xrightarrow{A}6 \xrightarrow{A} 7 \xrightarrow{B}14 と変化します。
S の長さを最小化する必要はありません。
Score : 300 points
Problem Statement
We have an empty box.
Takahashi can cast the following two spells any number of times in any order.
- Spell A: puts one new ball into the box.
- Spell B: doubles the number of balls in the box.
Tell us a way to have exactly N balls in the box with at most \mathbf{120} casts of spells.
It can be proved that there always exists such a way under the Constraints given.
There is no way other than spells to alter the number of balls in the box.
Constraints
- 1 \leq N \leq 10^{18}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
Output
Print a string S consisting of A and B.
The i-th character of S should represent the spell for the i-th cast.
S must have at most \mathbf{120} characters.
Sample Input 1
5
Sample Output 1
AABA
This changes the number of balls as follows: 0 \xrightarrow{A} 1\xrightarrow{A} 2 \xrightarrow{B}4\xrightarrow{A} 5.
There are also other acceptable outputs, such as AAAAA.
Sample Input 2
14
Sample Output 2
BBABBAAAB
This changes the number of balls as follows: 0 \xrightarrow{B} 0 \xrightarrow{B} 0 \xrightarrow{A}1 \xrightarrow{B} 2 \xrightarrow{B} 4 \xrightarrow{A}5 \xrightarrow{A}6 \xrightarrow{A} 7 \xrightarrow{B}14.
It is not required to minimize the length of S.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
それぞれ N 個、M 個の正整数からなる 2 つの数列 A=(A_1,A_2, \ldots ,A_N) と B=(B_1, \ldots ,B_M) が与えられます。
それぞれの数列から 1 つずつ要素を選んだときの 2 つの値の差の最小値、すなわち、 \displaystyle \min_{ 1\leq i\leq N}\displaystyle\min_{1\leq j\leq M} \lvert A_i-B_j\rvert を求めてください。
制約
- 1 \leq N,M \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
出力
答えを出力せよ。
入力例 1
2 2 1 6 4 9
出力例 1
2
それぞれの数列から 1 つずつ要素を選んだときの 2 つの値の差としてあり得るのは、 \lvert 1-4\rvert=3 、 \lvert 1-9\rvert=8 、 \lvert 6-4\rvert=2 、 \lvert 6-9\rvert=3 の 4 つです。 この中で最小である 2 を出力します。
入力例 2
1 1 10 10
出力例 2
0
入力例 3
6 8 82 76 82 82 71 70 17 39 67 2 45 35 22 24
出力例 3
3
Score : 300 points
Problem Statement
You are given two sequences: A=(A_1,A_2, \ldots ,A_N) consisting of N positive integers, and B=(B_1, \ldots ,B_M) consisting of M positive integers.
Find the minimum difference of an element of A and an element of B, that is, \displaystyle \min_{ 1\leq i\leq N}\displaystyle\min_{1\leq j\leq M} \lvert A_i-B_j\rvert.
Constraints
- 1 \leq N,M \leq 2\times 10^5
- 1 \leq A_i \leq 10^9
- 1 \leq B_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 A_2 \ldots A_N B_1 B_2 \ldots B_M
Output
Print the answer.
Sample Input 1
2 2 1 6 4 9
Sample Output 1
2
Here is the difference for each of the four pair of an element of A and an element of B: \lvert 1-4\rvert=3, \lvert 1-9\rvert=8, \lvert 6-4\rvert=2, and \lvert 6-9\rvert=3. We should print the minimum of these values, or 2.
Sample Input 2
1 1 10 10
Sample Output 2
0
Sample Input 3
6 8 82 76 82 82 71 70 17 39 67 2 45 35 22 24
Sample Output 3
3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
高橋君はすぬけ君たちを捕まえようとしています。
数直線上の座標 0,1,2,3,4 の 5 箇所に穴があり、すぬけ君たちの巣につながっています。
これから N 匹のすぬけ君が穴から出てきます。i 番目のすぬけ君は時刻 T_i に座標 X_i の穴から出てきて、大きさは A_i であることがわかっています。
高橋君は時刻 0 に座標 0 におり、数直線上を単位時間あたり 1 以下の速さで移動することができます。
すぬけ君が穴から出てきたのと同じ時刻に同じ座標に高橋君がいるとき、かつ、そのときに限り、高橋君はすぬけ君を捕まえることができます。
すぬけ君を捕まえるのにかかる時間は無視できます。
高橋君が適切に行動したとき、捕まえることができるすぬけ君の大きさの合計の最大値を求めてください。
制約
- 1 \leq N \leq 10^5
- 0 < T_1 < T_2 < \ldots < T_N \leq 10^5
- 0 \leq X_i \leq 4
- 1 \leq A_i \leq 10^9
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N T_1 X_1 A_1 T_2 X_2 A_2 \vdots T_N X_N A_N
出力
答えを整数として出力せよ。
入力例 1
3 1 0 100 3 3 10 5 4 1
出力例 1
101
次のように行動するのが最適です。
- 座標 0 で待機し、時刻 1 に 1 番目のすぬけ君を捕まえる
- 座標 4 へ移動し、時刻 5 に 3 番目のすぬけ君を捕まえる
1 番目と 2 番目のすぬけ君を両方とも捕まえることはできないので、これが最大です。
入力例 2
3 1 4 1 2 4 1 3 4 1
出力例 2
0
高橋君はすぬけ君を 1 匹も捕まえることができません。
入力例 3
10 1 4 602436426 2 1 623690081 3 3 262703497 4 4 628894325 5 3 450968417 6 1 161735902 7 1 707723857 8 2 802329211 9 0 317063340 10 2 125660016
出力例 3
2978279323
Score : 400 points
Problem Statement
Takahashi is trying to catch many Snuke.
There are five pits at coordinates 0, 1, 2, 3, and 4 on a number line, connected to Snuke's nest.
Now, N Snuke will appear from the pits. It is known that the i-th Snuke will appear from the pit at coordinate X_i at time T_i, and its size is A_i.
Takahashi is at coordinate 0 at time 0 and can move on the line at a speed of at most 1.
He can catch a Snuke appearing from a pit if and only if he is at the coordinate of that pit exactly when it appears.
The time it takes to catch a Snuke is negligible.
Find the maximum sum of the sizes of Snuke that Takahashi can catch by moving optimally.
Constraints
- 1 \leq N \leq 10^5
- 0 < T_1 < T_2 < \ldots < T_N \leq 10^5
- 0 \leq X_i \leq 4
- 1 \leq A_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N T_1 X_1 A_1 T_2 X_2 A_2 \vdots T_N X_N A_N
Output
Print the answer as an integer.
Sample Input 1
3 1 0 100 3 3 10 5 4 1
Sample Output 1
101
The optimal strategy is as follows.
- Wait at coordinate 0 to catch the first Snuke at time 1.
- Go to coordinate 4 to catch the third Snuke at time 5.
It is impossible to catch both the first and second Snuke, so this is the best he can.
Sample Input 2
3 1 4 1 2 4 1 3 4 1
Sample Output 2
0
Takahashi cannot catch any Snuke.
Sample Input 3
10 1 4 602436426 2 1 623690081 3 3 262703497 4 4 628894325 5 3 450968417 6 1 161735902 7 1 707723857 8 2 802329211 9 0 317063340 10 2 125660016
Sample Output 3
2978279323