A - Programming Education

Time Limit: 2 sec / Memory Limit: 1024 MB

配点: 100

問題文

2020 年, AtCoder 社は年商 10 億円を超え, プログラミング教育にも手を出すようになった.
ある日行われたテストでは, 1 才児は Hello World を出力するプログラムを, 2 才児は整数 A, B を入力して A+B を出力するプログラムを書かなければならない.
高橋君はこのテストを受けているが, 突然自分が何才なのかが分からなくなってしまった.
そこで, 最初に自分の年齢 N (N1 または 2) を入力し, N=1 ならば Hello World と出力し, N=2 ならば A, B を入力して A+B を出力するプログラムを作ることにした.
高橋君に代わって, このようなプログラムを作りなさい.

制約

  • N1 または 2
  • A1 以上 9 以下の整数
  • B1 以上 9 以下の整数

入力

入力は以下の 2 つのうちいずれかの形式で標準入力から与えられる.

1
2
A
B

出力

N=1 のとき, Hello World と出力し, N=2 のとき, A+B を出力しなさい.


入力例 1

1

出力例 1

Hello World

N=1 なので, 高橋君は 1 才である. したがって, Hello World を出力する.


入力例 2

2
3
5

出力例 2

8

N=2 なので, 高橋君は 2 才である. A=3, B=5 なので, A+B である 8 を出力する.

Score: 100 points

Problem Statement

In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.
One day, there was an exam where a one-year-old child must write a program that prints Hello World, and a two-year-old child must write a program that receives integers A, B and prints A+B.
Takahashi, who is taking this exam, suddenly forgets his age.
He decides to write a program that first receives his age N (1 or 2) as input, then prints Hello World if N=1, and additionally receives integers A, B and prints A+B if N=2.
Write this program for him.

Constraints

  • N is 1 or 2.
  • A is an integer between 1 and 9 (inclusive).
  • B is an integer between 1 and 9 (inclusive).

Input

Input is given from Standard Input in one of the following formats:

1
2
A
B

Output

If N=1, print Hello World; if N=2, print A+B.


Sample Input 1

1

Sample Output 1

Hello World

As N=1, Takahashi is one year old. Thus, we should print Hello World.


Sample Input 2

2
3
5

Sample Output 2

8

As N=2, Takahashi is two years old. Thus, we should print A+B, which is 8 since A=3 and B=5.

B - Time Limit Exceeded

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

外出している X さんは、ABC に参加するためにスマートウォッチで最適な帰宅経路を調べることにしました。

スマートウォッチであるあなたは、N 個の帰宅経路を見つけました。

X さんが i 番目の経路を使う場合、コスト c_i かけて時間 t_i で帰宅できます。

時間 T 以内に帰宅できる経路のうち、コストが最小となる経路のコストを求めてください。

制約

  • 入力はすべて整数である
  • 1 \leq N \leq 100
  • 1 \leq T \leq 1000
  • 1 \leq c_i \leq 1000
  • 1 \leq t_i \leq 1000
  • (c_i, t_i) の組は異なる

入力

入力は以下の形式で標準入力から与えられる。

N T
c_1 t_1
c_2 t_2
:
c_N t_N

出力

時間 T 以内に帰宅できる経路のうち、コストが最小となる経路のコストを出力せよ。

ただし、どの経路を使っても時間 T 以内に帰宅できない場合、TLE と出力せよ。


入力例 1

3 70
7 60
1 80
4 50

出力例 1

4
  • 1 番目の経路を使うと、コスト 7 で帰宅できます
  • 2 番目の経路では時間 T = 70 以内に帰宅できません
  • 3 番目の経路を使うと、コスト 4 で帰宅できます

従って、3 番目の経路を使ったときのコスト 4 が最小です。


入力例 2

4 3
1 1000
2 4
3 1000
4 500

出力例 2

TLE

どの経路を使っても時間 T = 3 以内に帰宅できません。


入力例 3

5 9
25 8
5 9
4 10
1000 1000
6 1

出力例 3

5

Score : 200 points

Problem Statement

When Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.

You, the smartwatch, has found N routes to his home.

If Mr. X uses the i-th of these routes, he will get home in time t_i at cost c_i.

Find the smallest cost of a route that takes not longer than time T.

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 100
  • 1 \leq T \leq 1000
  • 1 \leq c_i \leq 1000
  • 1 \leq t_i \leq 1000
  • The pairs (c_i, t_i) are distinct.

Input

Input is given from Standard Input in the following format:

N T
c_1 t_1
c_2 t_2
:
c_N t_N

Output

Print the smallest cost of a route that takes not longer than time T.

If there is no route that takes not longer than time T, print TLE instead.


Sample Input 1

3 70
7 60
1 80
4 50

Sample Output 1

4
  • The first route gets him home at cost 7.
  • The second route takes longer than time T = 70.
  • The third route gets him home at cost 4.

Thus, the cost 4 of the third route is the minimum.


Sample Input 2

4 3
1 1000
2 4
3 1000
4 500

Sample Output 2

TLE

There is no route that takes not longer than time T = 3.


Sample Input 3

5 9
25 8
5 9
4 10
1000 1000
6 1

Sample Output 3

5
C - Pyramid

Time Limit: 3 sec / Memory Limit: 1024 MB

配点: 300

問題文

古代すぬけ国では, AtCoder 社長「高橋君」の権威を高めるために, ピラミッドが建てられていた.
ピラミッドには 中心座標 (C_X, C_Y)高さ H が定まっており, 座標 (X, Y) の高度は max(H - |X - C_X| - |Y - C_Y|, 0) であった.

探検家の青木君は, このピラミッドの中心座標と高さを求めるために調査を行った. その結果, 次のような情報が得られた.

  • C_X, C_Y0 以上 100 以下の整数で, H1 以上の整数であった.
  • 上記と別に N 個の情報が得られた. そのうち i 個目の情報は, 「座標 (x_i, y_i) の高度は h_i である」

この情報は, ピラミッドの中心座標と高さを特定するのに十分であった. 情報を手掛かりに, これらの値を求めなさい.

制約

  • N1 以上 100 以下の整数
  • x_i, y_i0 以上 100 以下の整数
  • h_i0 以上 10^9 以下の整数
  • N 個の座標 (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) はすべて異なる
  • ピラミッドの中心座標と高さをちょうど 1 つに特定することができる

入力

入力は以下の形式で標準入力から与えられる.

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

出力

特定した中心座標と高さを表す整数 C_X, C_Y, H を空白区切りで, 1 行に出力しなさい.


入力例 1

4
2 3 5
2 1 5
1 2 5
3 2 5

出力例 1

2 2 6

この場合, 中心座標は (2, 2), 高さは 6 と特定することができる.


入力例 2

2
0 0 100
1 1 98

出力例 2

0 0 100

この場合, 中心座標は (0, 0), 高さは 100 と特定することができる.
C_X, C_Y0 以上 100 以下の整数であると分かっていることに注意せよ.


入力例 3

3
99 1 191
100 1 192
99 0 192

出力例 3

100 0 193

この場合, 中心座標は (100, 0), 高さは 193 と特定することができる.

Score: 300 points

Problem Statement

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.
The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:

  • C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.
  • Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Constraints

  • N is an integer between 1 and 100 (inclusive).
  • x_i and y_i are integers between 0 and 100 (inclusive).
  • h_i is an integer between 0 and 10^9 (inclusive).
  • The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.
  • The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.


Sample Input 1

4
2 3 5
2 1 5
1 2 5
3 2 5

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.


Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.
Note that C_X and C_Y are known to be integers between 0 and 100.


Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.

D - Partition

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

整数 N, M が与えられます。

a_1 + a_2 + ... + a_N = M となる正整数からなる長さ N の数列 a において、a_1, a_2, ..., a_N の最大公約数のとり得る最大値を求めてください。

制約

  • 入力はすべて整数である
  • 1 \leq N \leq 10^5
  • N \leq M \leq 10^9

入力

入力は以下の形式で標準入力から与えられる。

N M

出力

条件を満たす数列 a_1, a_2, ..., a_N の最大公約数のとり得る最大値を出力せよ。


入力例 1

3 14

出力例 1

2

(a_1, a_2, a_3) = (2, 4, 8) としたときこれらの最大公約数が 2 となり最大です。


入力例 2

10 123

出力例 2

3

入力例 3

100000 1000000000

出力例 3

10000

Score : 400 points

Problem Statement

You are given integers N and M.

Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 10^5
  • N \leq M \leq 10^9

Input

Input is given from Standard Input in the following format:

N M

Output

Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.


Sample Input 1

3 14

Sample Output 1

2

Consider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common divisor is 2, and this is the maximum value.


Sample Input 2

10 123

Sample Output 2

3

Sample Input 3

100000 1000000000

Sample Output 3

10000