Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
高橋村の長老はすぐに寝てしまいます。具体的には、最後に肩を叩かれてから S+0.5 秒以上経過すると長老は寝てしまいます。
現在、長老は起きており、付き人がちょうど長老の肩を叩きました。
これから付き人はちょうど N 回長老の肩を叩きます。i 回目の肩叩きは現在から T_i 秒後に行われます。
長老が現在から T_N 秒後まで連続して起きているかを判定してください。
制約
- 1 \leq N \leq 100
- 1 \leq S \leq 100
- 1 \leq T_i \leq 1000 (1 \leq i \leq N)
- T_i < T_{i+1} (1 \leq i \leq N-1)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N S T_1 T_2 \ldots T_N
出力
長老が現在から T_N 秒後まで連続して起きているならば Yes
を、そうでないならば No
を出力せよ。
入力例 1
5 10 6 11 21 22 30
出力例 1
Yes
付き人は時系列順に以下のように肩を叩きます。
- 6 秒後に肩を叩きます。このとき、長老は最後に肩を叩かれてから 6 秒しか経過していないので起きています。
- 11 秒後に肩を叩きます。このとき、長老は最後に肩を叩かれてから 5 秒しか経過していないので起きています。
- 21 秒後に肩を叩きます。このとき、長老は最後に肩を叩かれてから 10 秒しか経過していないので起きています。
- 22 秒後に肩を叩きます。このとき、長老は最後に肩を叩かれてから 1 秒しか経過していないので起きています。
- 30 秒後に肩を叩きます。このとき、長老は最後に肩を叩かれてから 8 秒しか経過していないので起きています。
現在から 30 秒後まで長老は起きているので、Yes
と出力します。
入力例 2
2 100 1 200
出力例 2
No
長老は現在から 101.5 秒後に寝てしまいます。そのため No
と出力します。
入力例 3
10 22 47 81 82 95 117 146 165 209 212 215
出力例 3
No
Score : 150 points
Problem Statement
The elder of Takahashi Village falls asleep immediately. Specifically, if S+0.5 seconds or more have passed since the elder was last tapped on the shoulder, the elder falls asleep.
Currently, the elder is awake, and an attendant has just tapped the elder on the shoulder.
From now on, the attendant will tap the elder's shoulder exactly N times. The i-th shoulder tap will be performed T_i seconds from now.
Determine whether the elder remains awake continuously from now until T_N seconds later.
Constraints
- 1 \leq N \leq 100
- 1 \leq S \leq 100
- 1 \leq T_i \leq 1000 (1 \leq i \leq N)
- T_i < T_{i+1} (1 \leq i \leq N-1)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N S T_1 T_2 \ldots T_N
Output
If the elder remains awake continuously from now until T_N seconds later, output Yes
; otherwise, output No
.
Sample Input 1
5 10 6 11 21 22 30
Sample Output 1
Yes
The attendant taps the shoulder in chronological order as follows:
- Taps after 6 seconds. At this time, only 6 seconds have passed since the elder was last tapped on the shoulder, so the elder is awake.
- Taps after 11 seconds. At this time, only 5 seconds have passed since the elder was last tapped on the shoulder, so the elder is awake.
- Taps after 21 seconds. At this time, only 10 seconds have passed since the elder was last tapped on the shoulder, so the elder is awake.
- Taps after 22 seconds. At this time, only 1 second has passed since the elder was last tapped on the shoulder, so the elder is awake.
- Taps after 30 seconds. At this time, only 8 seconds have passed since the elder was last tapped on the shoulder, so the elder is awake.
Since the elder is awake from now until 30 seconds later, output Yes
.
Sample Input 2
2 100 1 200
Sample Output 2
No
The elder falls asleep 101.5 seconds from now. Therefore, output No
.
Sample Input 3
10 22 47 81 82 95 117 146 165 209 212 215
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
AtCoder 村には N 本の橋があり、i 本目( i は 1 以上 N 以下の整数)の橋の高さは H_i です。
ここで、AtCoder 村にある N 本の橋のうち、どの相異なる 2 本の橋も高さが異なります。
AtCoder 村で最も高い橋は何本目の橋か出力してください。
制約
- 1\leq N \leq 100
- 1\leq H_i \leq 10^9
- H_i はすべて異なる
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N H_1 H_2 \ldots H_N
出力
AtCoder 村で最も高い橋は何本目の橋かを、整数で出力せよ。
入力例 1
3 50 80 70
出力例 1
2
AtCoder 村には 3 本の橋があります。
1,2,3 本目の橋の高さはそれぞれ, 50,80,70 であり、
最も高い橋は 2 本目の橋です。
よって、2 を出力します。
入力例 2
1 1000000000
出力例 2
1
AtCoder 村に橋が 1 本しか存在しないため、2 本目以降の橋は存在せず、最も高い橋は 1 本目の橋となります。
入力例 3
10 22 75 26 45 72 81 47 29 97 2
出力例 3
9
AtCoder 村には 10 本の橋があり、それらのうち最も高い橋は 9 番目の橋(高さは 97 )です。
Score : 100 points
Problem Statement
There are N bridges in AtCoder Village. The height of the bridge numbered i is H_i (i is an integer between 1 and N).
Every two different bridges in the village have different heights.
Print the number representing the highest bridge in the village.
Constraints
- 1\leq N \leq 100
- 1\leq H_i \leq 10^9
- All H_i are different.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N H_1 H_2 \ldots H_N
Output
Print the integer representing the highest bridge in AtCoder village.
Sample Input 1
3 50 80 70
Sample Output 1
2
The village has three bridges.
The first, second, and third bridges have heights of 50, 80, and 70, respectively,
so the second bridge is the highest.
Thus, 2 should be printed.
Sample Input 2
1 1000000000
Sample Output 2
1
The village has only one bridge, so the first bridge is the highest.
Sample Input 3
10 22 75 26 45 72 81 47 29 97 2
Sample Output 3
9
The village has ten bridges, and the ninth bridge (with a height of 97) is the highest.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
ナオヒロ君は N+1 個の連続する整数を 1 個ずつ持っていましたが、そのうち 1 個をなくしてしまいました。
残っている N 個の整数が順不同で A_1,\ldots,A_N として与えられるので、なくした整数を求めてください。
なお、なくした整数が一意に定まるような入力のみが与えられます。
制約
- 2 \leq N \leq 100
- 1 \leq A_i \leq 1000
- 入力は全て整数である
- なくした整数は一意に定まる
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
3 2 3 5
出力例 1
4
ナオヒロ君は初め 2,3,4,5 の 4 個の整数を持っており、4 をなくし、2,3,5 が残っていました。
なくした整数である 4 を出力します。
入力例 2
8 3 1 4 5 9 2 6 8
出力例 2
7
入力例 3
16 152 153 154 147 148 149 158 159 160 155 156 157 144 145 146 150
出力例 3
151
Score : 200 points
Problem Statement
Naohiro had N+1 consecutive integers, one of each, but he lost one of them.
The remaining N integers are given in arbitrary order as A_1,\ldots,A_N. Find the lost integer.
The given input guarantees that the lost integer is uniquely determined.
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 1000
- All input values are integers.
- The lost integer is uniquely determined.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
3 2 3 5
Sample Output 1
4
Naohiro originally had four integers, 2,3,4,5, then lost 4, and now has 2,3,5.
Print the lost integer, 4.
Sample Input 2
8 3 1 4 5 9 2 6 8
Sample Output 2
7
Sample Input 3
16 152 153 154 147 148 149 158 159 160 155 156 157 144 145 146 150
Sample Output 3
151
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 個のマスが左右一列に並んでおり、左から順にマス 1、マス 2、…、マス N と番号づけられています。
また、K 個のコマがあり、最初左から i 番目のコマはマス A_i に置かれています。
これらに対して、Q 回の操作を行います。
i 回目の操作では次の操作を行います。
- 左から L_i 番目のコマが一番右のマスにあるならば何も行わない。
- そうでない時、左から L_i 番目のコマがあるマスの 1 つ右のマスにコマが無いならば、左から L_i 番目のコマを 1 つ右のマスに移動させる。 1 つ右のマスにコマがあるならば、何も行わない。
Q 回の操作が終了した後の状態について、i=1,2,\ldots,K に対して左から i 番目のコマがあるマスの番号を出力してください。
制約
- 1\leq K\leq N\leq 200
- 1\leq A_1<A_2<\cdots<A_K\leq N
- 1\leq Q\leq 1000
- 1\leq L_i\leq K
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K Q A_1 A_2 \ldots A_K L_1 L_2 \ldots L_Q
出力
K 個の整数を空白区切りで一行に出力せよ。 ここで、i 個目の整数は、 Q 回の操作が終了した後の状態について、左から i 番目のコマの番号を表す。
入力例 1
5 3 5 1 3 4 3 3 1 1 2
出力例 1
2 4 5
最初、コマはマス 1, 3, 4 にあります。これに対して以下のように操作が行われます。
- 左から 3 番目のコマはマス 4 にあります。 これは一番右のマスでなく、その 1 つ右のマスにもコマが置かれていないため、左から 3 番目のコマをマス 5 に動かします。 コマはマス 1, 3, 5 にある状態になります。
- 左から 3 番目のコマはマス 5 にあります。 これは一番右のマスなので、何も行いません。 コマはマス 1, 3, 5 にある状態のままです。
- 左から 1 番目のコマはマス 1 にあります。 これは一番右のマスでなく、その 1 つ右のマスにもコマが置かれていないため、左から 1 番目のコマをマス 2 に動かします。 コマはマス 2, 3, 5 にある状態になります。
- 左から 1 番目のコマはマス 2 にあります。 これは一番右のマスでありませんが、その 1 つ右のマス(マス 3 )にコマが置かれているため、何も行いません。 コマはマス 2, 3, 5 にある状態のままです。
- 左から 2 番目のコマはマス 3 にあります。 これは一番右のマスでなく、その右のマスにもコマが置かれていないため、左から 2 番目のコマをマス 4 に動かします。 コマはマス 2, 4, 5 にある状態になります。
よって、Q 回の操作が終わった後でコマはマス 2, 4, 5 に置かれているため、2,4,5 を空白区切りでこの順に出力します。
入力例 2
2 2 2 1 2 1 2
出力例 2
1 2
入力例 3
10 6 9 1 3 5 7 8 9 1 2 3 4 5 6 5 6 2
出力例 3
2 5 6 7 9 10
Score : 200 points
Problem Statement
There are N squares, indexed Square 1, Square 2, …, Square N, arranged in a row from left to right.
Also, there are K pieces. The i-th piece from the left is initially placed on Square A_i.
Now, we will perform Q operations against them.
The i-th operation is as follows:
- If the L_i-th piece from the left is on its rightmost square, do nothing.
- Otherwise, move the L_i-th piece from the left one square right if there is no piece on the next square on the right; if there is, do nothing.
Print the index of the square on which the i-th piece from the left is after the Q operations have ended, for each i=1,2,\ldots,K.
Constraints
- 1\leq K\leq N\leq 200
- 1\leq A_1<A_2<\cdots<A_K\leq N
- 1\leq Q\leq 1000
- 1\leq L_i\leq K
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K Q A_1 A_2 \ldots A_K L_1 L_2 \ldots L_Q
Output
Print K integers in one line, with spaces in between. The i-th of them should be the index of the square on which the i-th piece from the left is after the Q operations have ended.
Sample Input 1
5 3 5 1 3 4 3 3 1 1 2
Sample Output 1
2 4 5
At first, the pieces are on Squares 1, 3, and 4. The operations are performed against them as follows:
- The 3-rd piece from the left is on Square 4. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 3-rd piece from the left to Square 5. Now, the pieces are on Squares 1, 3, and 5.
- The 3-rd piece from the left is on Square 5. This is the rightmost square, so do nothing. The pieces are still on Squares 1, 3, and 5.
- The 1-st piece from the left is on Square 1. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 1-st piece from the left to Square 2. Now, the pieces are on Squares 2, 3, and 5.
- The 1-st piece from the left is on Square 2. This is not the rightmost square, but the next square on the right (Square 3) contains a piece, so do nothing. The pieces are still on Squares 2, 3, and 5.
- The 2-nd piece from the left is on Square 3. This is not the rightmost square, and the next square on the right does not contain a piece, so move the 2-nd piece from the left to Square 4; Now, the pieces are still on Squares 2, 4, and 5.
Thus, after the Q operations have ended, the pieces are on Squares 2, 4, and 5, so 2, 4, and 5 should be printed in this order, with spaces in between.
Sample Input 2
2 2 2 1 2 1 2
Sample Output 2
1 2
Sample Input 3
10 6 9 1 3 5 7 8 9 1 2 3 4 5 6 5 6 2
Sample Output 3
2 5 6 7 9 10
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
1 から N の番号がついた N 人の人がいます。人 i は数 A_i を持っています。
「自分と同じ数を持っている人が自分以外の N-1 人の中に存在しない」という条件を満たす人のうち、持っている数が最大である人の番号を求めてください。
条件を満たす人が存在しない場合、代わりにそのことを報告してください。
制約
- 1 \leq N \leq 3\times 10^5
- 1 \leq A_i \leq 10^9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
「自分と同じ数を持っている人が自分以外の N-1 人の中に存在しない」という条件を満たす人が存在しない場合、-1
と出力せよ。
条件を満たす人が存在する場合、そのうち、持っている数が最大である人の番号を出力せよ。
入力例 1
9 2 9 9 7 9 2 4 5 8
出力例 1
9
「自分と同じ数を持っている人が自分以外の N-1 人の中に存在しない」という条件を満たすのは人 4,7,8,9 の 4 人です。
これらの人が持っている数はそれぞれ 7,4,5,8 であり、最大の数を持っているのは人 9 です。
よって答えは 9 となります。
入力例 2
4 1000000000 1000000000 998244353 998244353
出力例 2
-1
条件を満たす人が存在しない場合、-1
を出力してください。
Score : 300 points
Problem Statement
There are N people, labeled 1 to N. Person i has an integer A_i.
Among the people who satisfy the condition "None of the other N-1 people has the same integer as themselves," find the one with the greatest integer, and print that person's label.
If no person satisfies the condition, report that fact instead.
Constraints
- 1 \leq N \leq 3\times 10^5
- 1 \leq A_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
If no person satisfies the condition "None of the other N-1 people has the same integer as themselves," print -1
.
Otherwise, among those who satisfy it, print the label of the person whose integer is the largest.
Sample Input 1
9 2 9 9 7 9 2 4 5 8
Sample Output 1
9
Those who satisfy the condition are the persons labeled 4, 7, 8, and 9.
Their integers are 7, 4, 5, and 8, respectively, and the person with the largest integer is the person labeled 9.
Thus, the answer is 9.
Sample Input 2
4 1000000000 1000000000 998244353 998244353
Sample Output 2
-1
If no person satisfies the condition, print -1
.