A - Remaining Time

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 100

問題文

イルカはプログラミングコンテスト好きで、今日はAtCoderのコンテストに参加します。
現在時刻は、24 時間表記 (0:00〜23:59)A 時ちょうどであり、コンテストがちょうど B 時間後に始まります。
コンテストの開始時刻は、24 時間表記で何時ちょうどでしょうか?

制約

  • 0≦A,B≦23
  • A,B は整数である。

入力

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

A B

出力

コンテストの開始時刻を 24 時間表記で出力せよ。


入力例 1

9 12

出力例 1

21

現在時刻は 9 時ちょうどであり、その 12 時間後の時刻は 21 時ちょうどなので、21 と出力します。


入力例 2

19 0

出力例 2

19

今、コンテストが始まりました。


入力例 3

23 2

出力例 3

1

開始時刻は翌日の 1 時です。

Score : 100 points

Problem Statement

Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.
In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".
The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time.

Constraints

  • 0 \leq A,B \leq 23
  • A and B are integers.

Input

The input is given from Standard Input in the following format:

A B

Output

Print the hour of the starting time of the contest in 24-hour time.


Sample Input 1

9 12

Sample Output 1

21

In this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time.


Sample Input 2

19 0

Sample Output 2

19

The contest has just started.


Sample Input 3

23 2

Sample Output 3

1

The contest will begin at 1 o'clock the next day.

B - Checkpoints

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 200

問題文

xy 平面があり、その上に N 人の学生がいて、M 個のチェックポイントがあります。
i 番目の学生がいる座標は (a_i,b_i) (1≦i≦N) であり、番号 j のチェックポイントの座標は (c_j,d_j) (1≦j≦M) です。
これから合図があり、各学生はマンハッタン距離で一番近いチェックポイントに集合しなければなりません。
2つの地点 (x_1,y_1)(x_2,y_2) 間のマンハッタン距離は |x_1-x_2|+|y_1-y_2| で表されます。
ここで、|x|x の絶対値を表します。
ただし、一番近いチェックポイントが複数ある場合には、番号が最も小さいチェックポイントに移動することとします。
合図の後に、各学生がどのチェックポイントに移動するかを求めてください。

制約

  • 1≦N,M≦50
  • -10^8≦a_i,b_i,c_j,d_j≦10^8
  • 入力は全て整数である。

入力

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

N M
a_1 b_1
:  
a_N b_N
c_1 d_1
:  
c_M d_M

出力

解答を N 行に出力せよ。
i (1 ≦i≦N) 番目の行には、i 番目の学生が訪れるチェックポイントの番号を出力せよ。


入力例 1

2 2
2 0
0 0
-1 0
1 0

出力例 1

2
1

1 番目の学生と各チェックポイント間のマンハッタン距離は以下の通りです。

  • 番号 1 のチェックポイントへのマンハッタン距離は |2-(-1)|+|0-0|=3
  • 番号 2 のチェックポイントへのマンハッタン距離は |2-1|+|0-0|=1

したがって、最も近いチェックポイントの番号は 2 であるため、1 行目には 2 と出力します。

2 番目の学生と各チェックポイント間のマンハッタン距離は以下の通りです。

  • 番号 1 のチェックポイントへのマンハッタン距離は |0-(-1)|+|0-0|=1
  • 番号 2 のチェックポイントへのマンハッタン距離は |0-1|+|0-0|=1

最も近いチェックポイントが複数ある場合は、番号が最も小さいチェックポイントに移動するため、2 行目には 1 と出力します。


入力例 2

3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5

出力例 2

3
1
2

同じ座標に複数のチェックポイントが存在する場合もあります。


入力例 3

5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000

出力例 3

5
4
3
2
1

Score : 200 points

Problem Statement

There are N students and M checkpoints on the xy-plane.
The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.
The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.
Here, |x| denotes the absolute value of x.
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.
Which checkpoint will each student go to?

Constraints

  • 1 \leq N,M \leq 50
  • -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N M
a_1 b_1
:  
a_N b_N
c_1 d_1
:  
c_M d_M

Output

Print N lines.
The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.


Sample Input 1

2 2
2 0
0 0
-1 0
1 0

Sample Output 1

2
1

The Manhattan distance between the first student and each checkpoint is:

  • For checkpoint 1: |2-(-1)|+|0-0|=3
  • For checkpoint 2: |2-1|+|0-0|=1

The nearest checkpoint is checkpoint 2. Thus, the first line in the output should contain 2.

The Manhattan distance between the second student and each checkpoint is:

  • For checkpoint 1: |0-(-1)|+|0-0|=1
  • For checkpoint 2: |0-1|+|0-0|=1

When there are multiple nearest checkpoints, the student will go to the checkpoint with the smallest index. Thus, the second line in the output should contain 1.


Sample Input 2

3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5

Sample Output 2

3
1
2

There can be multiple checkpoints at the same coordinates.


Sample Input 3

5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000

Sample Output 3

5
4
3
2
1
C - Digits in Multiplication

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 300

問題文

整数 N が与えられます。
ここで、2 つの正の整数 A,B に対して、F(A,B) を「10 進表記における、A の桁数と B の桁数のうち大きい方」と定義します。
例えば、F(3,11) の値は、31 桁、112 桁であるため、F(3,11)=2 となります。
2 つの正の整数の組 (A,B)N=A×B を満たすように動くとき、F(A,B) の最小値を求めてください。

制約

  • 1≦N≦10^{10}
  • N は整数である。

入力

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

N

出力

2 つの正の整数の組 (A,B)N=A×B を満たすように動くときの F(A,B) の最小値を出力せよ。


入力例 1

10000

出力例 1

3

(A,B)=(100,100) のときに F(A,B) は最小値をとるため、F(100,100)=3 を出力します。


入力例 2

1000003

出力例 2

7

条件を満たす (A,B) の組は (1,1000003)(1000003,1)2 通りで、F(1,1000003)=F(1000003,1)=7 です。


入力例 3

9876543210

出力例 3

6

Score : 300 points

Problem Statement

You are given an integer N.
For two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B.
For example, F(3,11) = 2 since 3 has one digit and 11 has two digits.
Find the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B.

Constraints

  • 1 \leq N \leq 10^{10}
  • N is an integer.

Input

The input is given from Standard Input in the following format:

N

Output

Print the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B.


Sample Input 1

10000

Sample Output 1

3

F(A,B) has a minimum value of 3 at (A,B)=(100,100).


Sample Input 2

1000003

Sample Output 2

7

There are two pairs (A,B) that satisfy the condition: (1,1000003) and (1000003,1). For these pairs, F(1,1000003)=F(1000003,1)=7.


Sample Input 3

9876543210

Sample Output 3

6
D - Maximum Average Sets

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 400

問題文

N 個の品物が与えられます。
i 番目の品物の価値は v_i (1≦i≦N) です。
これらの品物から、A 個以上、B 個以下を選ばなければなりません。
この制約下において、選んだ品物の価値の平均の最大値を求めてください。
また、選んだ品物の平均が最大となるような品物の選び方が何通りあるかを求めてください。

制約

  • 1≦N≦50
  • 1≦A≦B≦N
  • 1≦v_i≦10^{15}
  • v_i は全て整数である。

入力

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

N A B
v_1 v_2 ... v_N  

出力

解答を 2 行に出力せよ。
1 行目には、選んだ品物の価値の平均の最大値を出力せよ。絶対誤差または相対誤差が 10^{−6} 以下ならば正解となる。
2 行目には、選んだ品物の平均が最大となるような品物の選び方の数を出力せよ。


入力例 1

5 2 2
1 2 3 4 5

出力例 1

4.500000
1

4 番目の品物と 5 番目の品物を選ぶと価値の平均が最大となるため、出力の 1 行目は 4.5 です。
また、それ以外の品物の選び方で価値の平均が 4.5 になるものはないため、出力の 2 行目は 1 です。


入力例 2

4 2 3
10 20 10 10

出力例 2

15.000000
3

価値の平均が最大となる品物の選び方は複数存在することがあります。


入力例 3

5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996

出力例 3

1000000000000000.000000
1

入力例 4

50 1 50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

出力例 4

1.000000
1125899906842623

Score : 400 points

Problem Statement

You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.

Constraints

  • 1 \leq N \leq 50
  • 1 \leq A,B \leq N
  • 1 \leq v_i \leq 10^{15}
  • Each v_i is an integer.

Input

The input is given from Standard Input in the following format:

N A B
v_1
v_2
...
v_N

Output

Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.


Sample Input 1

5 2 2
1 2 3 4 5

Sample Output 1

4.500000
1

The mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5.
There is no other way to select items so that the mean of the values will be 4.5, and thus the second line of the output should contain 1.


Sample Input 2

4 2 3
10 20 10 10

Sample Output 2

15.000000
3

There can be multiple ways to select items so that the mean of the values will be maximized.


Sample Input 3

5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996

Sample Output 3

1000000000000000.000000
1