Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
高橋君が 100 階建てのビルにいます。
高橋君は 2 階分までの上り、または、3 階分までの下りであれば移動には階段を使い、そうでないときエレベーターを使います。
高橋君が X 階から Y 階への移動に使うのは階段ですか?
制約
- 1 \leq X,Y \leq 100
- X \neq Y
- 入力は全ては整数である
入力
入力は以下の形式で標準入力から与えられる。
X Y
出力
移動に使うのが階段ならば Yes
、エレベーターならば No
を出力せよ。
入力例 1
1 4
出力例 1
No
1 階から 4 階への移動は 3 階分の上りなのでエレベーターを使います。
入力例 2
99 96
出力例 2
Yes
99 階から 96 階への移動は 3 階分の下りなので階段を使います。
入力例 3
100 1
出力例 3
No
Score : 100 points
Problem Statement
Takahashi is in a building with 100 floors.
He uses the stairs for moving up two floors or less or moving down three floors or less, and uses the elevator otherwise.
Does he use the stairs to move from floor X to floor Y?
Constraints
- 1 \leq X,Y \leq 100
- X \neq Y
- All input values are integers.
Input
The input is given from Standard Input in the following format:
X Y
Output
If Takahashi uses the stairs for the move, print Yes
; if he uses the elevator, print No
.
Sample Input 1
1 4
Sample Output 1
No
The move from floor 1 to floor 4 involves going up three floors, so Takahashi uses the elevator.
Sample Input 2
99 96
Sample Output 2
Yes
The move from floor 99 to floor 96 involves going down three floors, so Takahashi uses the stairs.
Sample Input 3
100 1
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
整数 N が与えられます。
N が -2^{31} 以上かつ 2^{31} 未満ならば Yes
を、そうでないならば No
を出力してください。
制約
- -2^{63} \leq N < 2^{63}
- N は整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
N が -2^{31} 以上かつ 2^{31} 未満ならば Yes
を、そうでないならば No
を出力せよ。
入力例 1
10
出力例 1
Yes
10 は -2^{31} 以上かつ 2^{31} 未満であるので、Yes
を出力します。
入力例 2
-9876543210
出力例 2
No
-9876543210 は -2^{31} 未満であるので、No
を出力します。
入力例 3
483597848400000
出力例 3
No
483597848400000 は 2^{31} 以上であるので、No
を出力します。
Score : 100 points
Problem Statement
You are given an integer N.
If N is between -2^{31} and 2^{31}-1 (inclusive), print Yes
; otherwise, print No
.
Constraints
- -2^{63} \leq N < 2^{63}
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If N is between -2^{31} and 2^{31}-1 (inclusive), print Yes
; otherwise, print No
.
Sample Input 1
10
Sample Output 1
Yes
10 is between -2^{31} and 2^{31}-1, so Yes
should be printed.
Sample Input 2
-9876543210
Sample Output 2
No
-9876543210 is less than -2^{31}, so No
should be printed.
Sample Input 3
483597848400000
Sample Output 3
No
483597848400000 is greater than 2^{31}-1, so No
should be printed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 人が 1 列に並んでおり、前から i 番目に並んでいる人は人 P_i です。
Q 個のクエリを処理して下さい。i 番目のクエリは以下のものです。
- 整数 A_i,B_i が与えられる。人 A_i と人 B_i のうち、より前に並んでいる人の番号を出力せよ。
制約
- 入力は全て整数
- 1\leq N\leq 100
- 1\leq P_i\leq N
- P_i \neq P_j\ (i\neq j)
- 1\leq Q \leq 100
- 1\leq A_i<B_i\leq N
入力
入力は以下の形式で標準入力から与えられる。
N P_1 \ldots P_N Q A_1 B_1 \vdots A_Q B_Q
出力
Q 行出力せよ。i 行目には、i 番目のクエリの答えを出力せよ。
入力例 1
3 2 1 3 3 2 3 1 2 1 3
出力例 1
2 2 1
1 番目のクエリでは、人 2 は前から 1 番目、人 3 は前から 3 番目なので、人 2 がより前にいます。
2 番目のクエリでは、人 1 は前から 2 番目、人 2 は前から 1 番目なので、人 2 がより前にいます。
3 番目のクエリでは、人 1 は前から 2 番目、人 3 は前から 3 番目なので、人 1 がより前にいます。
入力例 2
7 3 7 2 1 6 5 4 13 2 3 1 2 1 3 3 6 3 7 2 4 3 7 1 3 4 7 1 6 2 4 1 3 1 3
出力例 2
3 2 3 3 3 2 3 3 7 1 2 3 3
Score: 200 points
Problem Statement
There are N people standing in a line. The person standing at the i-th position from the front is person P_i.
Process Q queries. The i-th query is as follows:
- You are given integers A_i and B_i. Between person A_i and person B_i, print the person number of the person standing further to the front.
Constraints
- All inputs are integers.
- 1 \leq N \leq 100
- 1 \leq P_i \leq N
- P_i \neq P_j\ (i \neq j)
- 1 \leq Q \leq 100
- 1 \leq A_i < B_i \leq N
Input
The input is given from Standard Input in the following format:
N P_1 \ldots P_N Q A_1 B_1 \vdots A_Q B_Q
Output
Print Q lines. The i-th line should contain the response for the i-th query.
Sample Input 1
3 2 1 3 3 2 3 1 2 1 3
Sample Output 1
2 2 1
In the first query, person 2 is at the first position from the front, and person 3 is at the third position, so person 2 is further to the front.
In the second query, person 1 is at the second position from the front, and person 2 is at the first position, so person 2 is further to the front.
In the third query, person 1 is at the second position from the front, and person 3 is at the third position, so person 1 is further to the front.
Sample Input 2
7 3 7 2 1 6 5 4 13 2 3 1 2 1 3 3 6 3 7 2 4 3 7 1 3 4 7 1 6 2 4 1 3 1 3
Sample Output 2
3 2 3 3 3 2 3 3 7 1 2 3 3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 人の人がおり、i 人目 (1\leq i\leq N) の現在の髪の長さは L_i です。
すべての人は 1 日経つごとに髪の長さが 1 ずつ増えます。
髪の長さが T 以上の人が初めて P 人以上になるのは現在から何日後か出力してください。
ただし、現在の時点ですでに髪の長さが T 以上の人が P 人以上にいる場合は 0 を出力してください。
制約
- 1\leq N\leq 100
- 1\leq L_i\leq 100
- 1\leq T\leq 100
- 1\leq P\leq N
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N T P L_1 L_2 \ldots L_N
出力
髪の長さが T 以上の人が初めて P 人以上になるのは現在から何日後か出力せよ。 ただし、現在の時点ですでに条件をみたしている場合は 0 を出力せよ。
入力例 1
5 10 3 3 11 1 6 2
出力例 1
7
5 人の人がおり、現在の時点で髪の長さはそれぞれ 3,11,1,6,2 であるため、髪の長さが 10 以上の人は 1 人です。
現在から 7 日後にはそれぞれの人の髪の長さは順に 10,18,8,13,9 となり、髪の長さが 10 以上の人は 3 人となります。
現在から 6 日後の時点では髪の長さが 10 以上の人は 2 人であるため条件をみたしておらず、よって 7 を出力します。
入力例 2
2 5 2 10 10
出力例 2
0
現在の時点ですでに髪の長さが 5 以上の人が 2 人いるため条件をみたしており、0 を出力します。
入力例 3
3 10 1 1 2 3
出力例 3
7
Score : 200 points
Problem Statement
There are N people, and the current hair length of the i-th person (1 \leq i \leq N) is L_i.
Each person's hair grows by 1 per day.
Print the number of days after which the number of people whose hair length is at least T becomes P or more for the first time.
If there are already P or more people whose hair length is at least T now, print 0.
Constraints
- 1 \leq N \leq 100
- 1 \leq L_i \leq 100
- 1 \leq T \leq 100
- 1 \leq P \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N T P L_1 L_2 \ldots L_N
Output
Print the number of days after which the number of people whose hair length is at least T becomes P or more for the first time. If this condition is already satisfied now, print 0.
Sample Input 1
5 10 3 3 11 1 6 2
Sample Output 1
7
There are five people, and their current hair lengths are 3, 11, 1, 6, 2, so there is one person whose hair length is at least 10.
After seven days, the hair lengths of the people will be 10, 18, 8, 13, 9, respectively, and there will be three people whose hair length is at least 10.
After six days, there are only two people whose hair length is at least 10, not satisfying the condition, so print 7.
Sample Input 2
2 5 2 10 10
Sample Output 2
0
Since there are already two people whose hair length is at least 5 now, satisfying the condition, so print 0.
Sample Input 3
3 10 1 1 2 3
Sample Output 3
7
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
一台のバスが走っています。バスの乗客の数は常に非負整数です。
このバスにはある時点で 0 人以上の乗客が乗っており、その時点から現在までに N 回停車しました。このうち i 回目の停車では乗客が差し引き A_i 人増えました。A_i は負の値であることもあり、その場合は乗客が差し引き -A_i 人減ったことを意味しています。また、停車時以外には乗客の乗り降りはありませんでした。
与えられた情報に矛盾しない現在のバスの乗客の数として考えられる最小値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- -10^9 \leq A_i \leq 10^9
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
4 3 -5 7 -4
出力例 1
3
はじめに乗っている乗客の人数が 2 人であるとき、現在の乗客の人数は 2 + 3 + (-5) + 7 + (-4) = 3 人であり、さらにバスの乗客の人数は常に非負整数となります。
入力例 2
5 0 0 0 0 0
出力例 2
0
入力例 3
4 -1 1000000000 1000000000 1000000000
出力例 3
3000000000
Score: 250 points
Problem Statement
A bus is in operation. The number of passengers on the bus is always a non-negative integer.
At some point in time, the bus had zero or more passengers, and it has stopped N times since then. At the i-th stop, the number of passengers increased by A_i. Here, A_i can be negative, meaning the number of passengers decreased by -A_i. Also, no passengers got on or off the bus other than at the stops.
Find the minimum possible current number of passengers on the bus that is consistent with the given information.
Constraints
- 1 \leq N \leq 2 \times 10^5
- -10^9 \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
Print the answer.
Sample Input 1
4 3 -5 7 -4
Sample Output 1
3
If the initial number of passengers was 2, the current number of passengers would be 2 + 3 + (-5) + 7 + (-4) = 3, and the number of passengers on the bus would have always been a non-negative integer.
Sample Input 2
5 0 0 0 0 0
Sample Output 2
0
Sample Input 3
4 -1 1000000000 1000000000 1000000000
Sample Output 3
3000000000