Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
整数 N が与えられます。
以下の指示に従って N の近似値を出力してください。
- N が 10^3-1 以下ならば、N をそのまま出力する。
- N が 10^3 以上 10^4-1 以下ならば、N の一の位を切り捨てて出力する。
- N が 10^4 以上 10^5-1 以下ならば、N の十の位以下を切り捨てて出力する。
- N が 10^5 以上 10^6-1 以下ならば、N の百の位以下を切り捨てて出力する。
- N が 10^6 以上 10^7-1 以下ならば、N の千の位以下を切り捨てて出力する。
- N が 10^7 以上 10^8-1 以下ならば、N の一万の位以下を切り捨てて出力する。
- N が 10^8 以上 10^9-1 以下ならば、N の十万の位以下を切り捨てて出力する。
制約
- N は 0 以上 10^9-1 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
20230603
出力例 1
20200000
20230603 は 10^7 以上 10^8-1 以下です。
したがって、一万以下の位を切り捨てて 20200000 を出力します。
入力例 2
0
出力例 2
0
入力例 3
304
出力例 3
304
入力例 4
500600
出力例 4
500000
Score : 200 points
Problem Statement
You are given an integer N.
Print an approximation of N according to the following instructions.
- If N is less than or equal to 10^3-1, print N as it is.
- If N is between 10^3 and 10^4-1, inclusive, truncate the ones digit of N and print the result.
- If N is between 10^4 and 10^5-1, inclusive, truncate the tens digit and all digits below it of N and print the result.
- If N is between 10^5 and 10^6-1, inclusive, truncate the hundreds digit and all digits below it of N and print the result.
- If N is between 10^6 and 10^7-1, inclusive, truncate the thousands digit and all digits below it of N and print the result.
- If N is between 10^7 and 10^8-1, inclusive, truncate the ten-thousands digit and all digits below it of N and print the result.
- If N is between 10^8 and 10^9-1, inclusive, truncate the hundred-thousands digit and all digits below it of N and print the result.
Constraints
- N is an integer between 0 and 10^9-1, inclusive.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
20230603
Sample Output 1
20200000
20230603 is between 10^7 and 10^8-1 (inclusive).
Therefore, truncate the ten-thousands digit and all digits below it, and print 20200000.
Sample Input 2
0
Sample Output 2
0
Sample Input 3
304
Sample Output 3
304
Sample Input 4
500600
Sample Output 4
500000
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
以下のような N 個の整数列 A_0,\ldots,A_{N-1} を求めてください。
- 各 i (0\leq i \leq N-1) について、A_i の長さは i+1 である。
-
各 i,j (0\leq i \leq N-1, 0 \leq j \leq i) について、A_i の j+1 番目の値 a_{i,j} は次のように定められる。
- j=0 または j=i の時、a_{i,j}=1
- それ以外の時、a_{i,j} = a_{i-1,j-1} + a_{i-1,j}
制約
- 1 \leq N \leq 30
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
N 行出力せよ。 i 行目には A_{i-1} の値を順に空白区切りで出力せよ。
入力例 1
3
出力例 1
1 1 1 1 2 1
入力例 2
10
出力例 2
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1
Score : 200 points
Problem Statement
Find the N integer sequences A_0,\ldots,A_{N-1} defined as follows.
- For each i (0\leq i \leq N-1), the length of A_i is i+1.
- For each i and j (0\leq i \leq N-1, 0 \leq j \leq i), the (j+1)-th term of A_i, denoted by a_{i,j}, is defined as follows.
- a_{i,j}=1, if j=0 or j=i.
- a_{i,j} = a_{i-1,j-1} + a_{i-1,j}, otherwise.
Constraints
- 1 \leq N \leq 30
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print N lines. The i-th line should contain the terms of A_{i-1} separated by spaces.
Sample Input 1
3
Sample Output 1
1 1 1 1 2 1
Sample Input 2
10
Sample Output 2
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
あるイベントには N 人が参加し、i 番目の人の交通費は A_i 円でした。
イベントの主催者である高橋くんは、交通費補助額の上限額 x を設定して、人 i には交通費補助額として \min(x,A_i) 円を支給することとしました。ここで x は非負整数である必要があります。
高橋くんの予算が M 円であり、N 人に渡す交通費補助額の総和を M 円以下にしたいとき、交通費補助額の上限額 x は最大でいくらにできますか?
ただし、交通費補助額の上限額を無限に大きくできる場合は代わりにそのことを報告してください。
制約
- 1\leq N\leq 2\times 10^5
- 1\leq M \leq 2\times 10^{14}
- 1\leq A_i \leq 10^9
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M
A_1 A_2 \ldots A_{N}
出力
予算の条件を満たすときの交通費補助額の上限額 x の最大値を整数として出力せよ。
ただし、交通費補助額の上限額を無限に大きくできる場合は代わりに infinite と出力せよ。
入力例 1
4 8 1 3 2 4
出力例 1
2
交通費補助額の上限額を 2 円にすると、N 人に渡す交通費補助額の総和は \min(2,1) + \min(2,3) + \min(2,2) + \min(2,4) = 7 円となり、予算の 8 円以下となります。
交通費補助額の上限額を 3 円にすると、N 人に渡す交通費補助額の総和は \min(3,1) + \min(3,3) + \min(3,2) + \min(3,4) = 9 円となり、予算の 8 円を超えてしまいます。
よって、交通費補助額の上限額の最大値は 2 円となります。
入力例 2
3 20 5 3 2
出力例 2
infinite
交通費補助額の上限額を無限に大きくできます。
入力例 3
10 23 2 5 6 5 2 1 7 9 7 2
出力例 3
2
Score : 300 points
Problem Statement
There are N people participating in an event, and the transportation cost for the i-th person is A_i yen.
Takahashi, the organizer of the event, decided to set a maximum limit x for the transportation subsidy. The subsidy for person i will be \min(x, A_i) yen. Here, x must be a non-negative integer.
Given that Takahashi's budget is M yen, and he wants the total transportation subsidy for all N people to be at most M yen, what is the maximum possible value of the subsidy limit x?
If the subsidy limit can be made infinitely large, report that instead.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^{14}
- 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 M
A_1 A_2 \ldots A_{N}
Output
Print the maximum value of the subsidy limit x that satisfies the budget condition, as an integer.
If the subsidy limit can be made infinitely large, print infinite instead.
Sample Input 1
4 8 1 3 2 4
Sample Output 1
2
If the subsidy limit is set to 2 yen, the total transportation subsidy for all N people is \min(2,1) + \min(2,3) + \min(2,2) + \min(2,4) = 7 yen, which is within the budget of 8 yen.
If the subsidy limit is set to 3 yen, the total transportation subsidy for all N people is \min(3,1) + \min(3,3) + \min(3,2) + \min(3,4) = 9 yen, which exceeds the budget of 8 yen.
Therefore, the maximum possible value of the subsidy limit is 2 yen.
Sample Input 2
3 20 5 3 2
Sample Output 2
infinite
The subsidy limit can be made infinitely large.
Sample Input 3
10 23 2 5 6 5 2 1 7 9 7 2
Sample Output 3
2
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
2 次元座標平面があります。x 軸正方向を右向き、y 軸正方向を上向きとします。
この平面上に自己交差のない四角形があります。
4 つの頂点の座標は反時計回りに (A_x,A_y),(B_x,B_y),(C_x,C_y),(D_x,D_y) です。
この四角形が凸であるか判定してください。
なお、四角形の 4 つの内角が全て 180 度未満であるとき、かつ、その時に限り、その四角形は凸であるといいます。
制約
- -100 \leq A_x,A_y,B_x,B_y,C_x,C_y,D_x,D_y \leq 100
- 入力に含まれる値は全て整数である
- 与えられる 4 点は四角形の 4 頂点を反時計回りに並べたものである
- 与えられる 4 点のなす四角形は自己交差がなく退化していない。すなわち
- どの 2 頂点も同じ座標にない
- どの 3 頂点も同一直線上にない
- 隣接しない 2 辺は共有点を持たない
入力
入力は以下の形式で標準入力から与えられる。
A_x A_y B_x B_y C_x C_y D_x D_y
出力
与えられる四角形が凸なら Yes、凸でないなら No を出力せよ。
入力例 1
0 0 1 0 1 1 0 1
出力例 1
Yes
与えられた四角形は正方形であり、4 つの内角は全て 90 度です。したがって、この四角形は凸です。

入力例 2
0 0 1 1 -1 0 1 -1
出力例 2
No
角 A が 270 度です。したがって、この四角形は凸ではありません。

Score : 300 points
Problem Statement
Consider a two-dimensional coordinate plane, where the x-axis is oriented to the right, and the y-axis is oriented upward.
In this plane, there is a quadrilateral without self-intersection.
The coordinates of the four vertices are (A_x,A_y), (B_x,B_y), (C_x,C_y), and (D_x,D_y), in counter-clockwise order.
Determine whether this quadrilateral is convex.
Here, a quadrilateral is convex if and only if all four interior angles are less than 180 degrees.
Constraints
- -100 \leq A_x,A_y,B_x,B_y,C_x,C_y,D_x,D_y \leq 100
- All values in input are integers.
- The given four points are the four vertices of a quadrilateral in counter-clockwise order.
- The quadrilateral formed by the given four points has no self-intersection and is non-degenerate. That is,
- no two vertices are at the same coordinates;
- no three vertices are colinear; and
- no two edges that are not adjacent have a common point.
Input
Input is given from Standard Input in the following format:
A_x A_y B_x B_y C_x C_y D_x D_y
Output
If the given quadrilateral is convex, print Yes; otherwise, print No.
Sample Input 1
0 0 1 0 1 1 0 1
Sample Output 1
Yes
The given quadrilateral is a square, whose four interior angles are all 90 degrees. Thus, this quadrilateral is convex.

Sample Input 2
0 0 1 1 -1 0 1 -1
Sample Output 2
No
The angle A is 270 degrees. Thus, this quadrilateral is not convex.

Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
長さ N の整数列 A=(A_1,A_2,\dots,A_N) が与えられます。
長さ M の A の部分列(連続でなくてもよい) B=(B_1,B_2,\dots,B_M) に対する、\displaystyle \sum_{i=1}^{M} i \times B_i の最大値を求めてください。
注記
数列の部分列とは、数列から 0 個以上の要素を取り除いた後、残りの要素を元の順序で連結して得られる数列のことをいいます。
例えば、(10,30) は (10,20,30) の部分列ですが、(20,10) は (10,20,30) の部分列ではありません。
制約
- 1 \le M \le N \le 2000
- - 2 \times 10^5 \le A_i \le 2 \times 10^5
- 入力は全て整数。
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
4 2 5 4 -1 8
出力例 1
21
B=(A_1,A_4) とした場合、\displaystyle \sum_{i=1}^{M} i \times B_i = 1 \times 5 + 2 \times 8 = 21 となります。22 以上の値を達成することはできないため、解は 21 です。
入力例 2
10 4 -3 1 -4 1 -5 9 -2 6 -5 3
出力例 2
54
Score : 400 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,\dots,A_N) of length N.
Find the maximum value of \displaystyle \sum_{i=1}^{M} i \times B_i for a (not necessarily contiguous) subsequence B=(B_1,B_2,\dots,B_M) of length M of A.
Notes
A subsequence of a number sequence is a sequence that is obtained by removing 0 or more elements from the original number sequence and concatenating the remaining elements without changing the order.
For example, (10,30) is a subsequence of (10,20,30), but (20,10) is not a subsequence of (10,20,30).
Constraints
- 1 \le M \le N \le 2000
- - 2 \times 10^5 \le A_i \le 2 \times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N
Output
Print the answer.
Sample Input 1
4 2 5 4 -1 8
Sample Output 1
21
When B=(A_1,A_4), we have \displaystyle \sum_{i=1}^{M} i \times B_i = 1 \times 5 + 2 \times 8 = 21. Since it is impossible to achieve 22 or a larger value, the solution is 21.
Sample Input 2
10 4 -3 1 -4 1 -5 9 -2 6 -5 3
Sample Output 2
54