Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
A
, B
, C
からなる長さ N の文字列 S が与えられます。
S の中で ABC
が(連続な)部分文字列として初めて現れる位置を答えてください。すなわち、以下の条件を全て満たす整数 n のうち最小のものを答えてください。
- 1 \leq n \leq N - 2
- S の n 文字目から n+2 文字目までを取り出して出来る文字列は
ABC
である。
ただし、ABC
が S に現れない場合は -1
を出力してください。
制約
- 3 \leq N \leq 100
- S は
A
,B
,C
からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
S の中で ABC
が部分文字列として初めて現れる位置を出力せよ。ただし、ABC
が S に現れない場合は -1
を出力せよ。
入力例 1
8 ABABCABC
出力例 1
3
S の中で ABC
が初めて現れるのは 3 文字目から 5 文字目までの位置です。よって 3 が答えになります。
入力例 2
3 ACB
出力例 2
-1
ABC
が S に現れない場合は -1 を出力してください。
入力例 3
20 BBAAABBACAACABCBABAB
出力例 3
13
Score : 100 points
Problem Statement
You are given a string S of length N consisting of A
, B
, and C
.
Find the position where ABC
first appears as a (contiguous) substring in S. In other words, find the smallest integer n that satisfies all of the following conditions.
- 1 \leq n \leq N - 2.
- The string obtained by extracting the n-th through (n+2)-th characters of S is
ABC
.
If ABC
does not appear in S, print -1
.
Constraints
- 3 \leq N \leq 100
- S is a string of length N consisting of
A
,B
, andC
.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the position where ABC
first appears as a substring in S, or -1
if it does not appear in S.
Sample Input 1
8 ABABCABC
Sample Output 1
3
ABC
first appears in S at the 3-rd through 5-th characters of S. Therefore, the answer is 3.
Sample Input 2
3 ACB
Sample Output 2
-1
If ABC
does not appear in S, print -1.
Sample Input 3
20 BBAAABBACAACABCBABAB
Sample Output 3
13
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
3 文字からなる文字列 S が与えられます。S は、1 以上 9 以下の整数 a, b と文字 x
を、axb
のように順につなげて得られます。
a と b の積を求めてください。
制約
- S の長さは 3
- S の 1 文字目および 3 文字目は 1 以上 9 以下の整数を表す
- S の 2 文字目は
x
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
3x7
出力例 1
21
3 \times 7 = 21 であるので、これを出力します。
入力例 2
9x9
出力例 2
81
入力例 3
1x1
出力例 3
1
Score : 100 points
Problem Statement
You are given a 3-character string S, which is a concatenation of integers a and b between 1 and 9 (inclusive) and the character x
in this order: axb
.
Find the product of a and b.
Constraints
- The length of S is 3.
- The 1-st and 3-rd characters are digits between 1 and 9 (inclusive).
- The 2-nd character is
x
.
Input
Input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
3x7
Sample Output 1
21
We have 3 \times 7 = 21, which should be printed.
Sample Input 2
9x9
Sample Output 2
81
Sample Input 3
1x1
Sample Output 3
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ N の整数列 A=(A_1,A_2,\ldots,A_N) 及び整数 L,R が与えられます。ここで L,R は L\leq R を満たします。
i=1,2,\ldots,N について以下の 2 つの条件を共に満たす整数 X_i を求めてください。なお、求める整数は常に一意に定まります。
- L\leq X_i \leq R
- L 以上 R 以下であるようなどの整数 Y についても |X_i - A_i| \leq |Y-A_i| を満たす
制約
- 1\leq N\leq 2\times 10^5
- 1\leq L\leq R \leq 10^9
- 1\leq A_i\leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N L R A_1 \ldots A_N
出力
i=1,2,\ldots,N について X_i を空白区切りで出力せよ。
入力例 1
5 4 7 3 1 4 9 7
出力例 1
4 4 4 7 7
i=1 では、
- |4-3|=1
- |5-3|=2
- |6-3|=3
- |7-3|=4
より X_i = 4 です。
入力例 2
3 10 10 11 10 9
出力例 2
10 10 10
Score : 200 points
Problem Statement
You are given an integer sequence A=(A_1,A_2,\ldots,A_N) of length N and integers L and R such that L\leq R.
For each i=1,2,\ldots,N, find the integer X_i that satisfies both of the following conditions. Note that the integer to be found is always uniquely determined.
- L\leq X_i \leq R.
- For every integer Y such that L \leq Y \leq R, it holds that |X_i - A_i| \leq |Y - A_i|.
Constraints
- 1\leq N\leq 2\times 10^5
- 1\leq L\leq R \leq 10^9
- 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 L R A_1 \ldots A_N
Output
Print X_i for i=1,2,\ldots,N, separated by spaces.
Sample Input 1
5 4 7 3 1 4 9 7
Sample Output 1
4 4 4 7 7
For i=1:
- |4-3|=1
- |5-3|=2
- |6-3|=3
- |7-3|=4
Thus, X_i = 4.
Sample Input 2
3 10 10 11 10 9
Sample Output 2
10 10 10
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 点
問題文
長さ N の非負整数列 A が与えられます。
A から K 要素を選んで順序を保ったまま抜き出した列を B としたとき、 MEX(B) としてありえる最大値を求めてください。
但し、数列 X に対して MEX(X) は以下の条件を満たす唯一の非負整数 m として定義されます。
- 0 \le i < m を満たす全ての整数 i が X に含まれる。
- m が X に含まれない。
制約
- 入力は全て整数
- 1 \le K \le N \le 3 \times 10^5
- 0 \le A_i \le 10^9
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
7 3 2 0 2 3 2 1 9
出力例 1
3
この入力では A=(2,0,2,3,2,1,9) であり、ここから K=3 要素を選んで抜き出して数列 B を得ます。例えば、
- 1,2,3 要素目を抜き出した時、 MEX(B)=MEX(2,0,2)=1
- 3,4,6 要素目を抜き出した時、 MEX(B)=MEX(2,3,1)=0
- 2,6,7 要素目を抜き出した時、 MEX(B)=MEX(0,1,9)=2
- 2,3,6 要素目を抜き出した時、 MEX(B)=MEX(0,2,1)=3
のようになります。
達成可能な MEX の最大値は 3 です。
Score : 300 points
Problem Statement
You are given a length-N sequence of non-negative integers.
When B is a sequence obtained by choosing K elements from A and concatenating them without changing the order, find the maximum possible value of MEX(B).
Here, for a sequence X, we define MEX(X) as the unique non-negative integer m that satisfies the following conditions:
- Every integer i such that 0 \le i < m is contained in X.
- m is not contained in X.
Constraints
- All values in the input are integers.
- 1 \le K \le N \le 3 \times 10^5
- 0 \le A_i \le 10^9
Input
The input is given from Standard Input in the following format:
N K A_1 A_2 \dots A_N
Output
Print the answer.
Sample Input 1
7 3 2 0 2 3 2 1 9
Sample Output 1
3
In this input, A=(2,0,2,3,2,1,9), and you obtain the sequence B by picking K=3 elements. For example,
- If the 1-st, 2-nd, and 3-rd elements are chosen, MEX(B)=MEX(2,0,2)=1.
- If the 3-rd, 4-th, and 6-th elements are chosen, MEX(B)=MEX(2,3,1)=0.
- If the 2-nd, 6-th, and 7-th elements are chosen, MEX(B)=MEX(0,1,9)=2.
- If the 2-nd, 3-rd, and 6-th elements are chosen, MEX(B)=MEX(0,2,1)=3.
The maximum possible MEX is 3.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 250 点
問題文
N 種類のビーンズが 1 粒ずつあります。 i 種類目のビーンズはおいしさが A_i で色が C_i です。ビーンズは混ぜられており、色でしか区別することができません。
あなたはビーンズの色を 1 つ選び、その色のビーンズをどれか 1 粒食べます。ビーンズの色をうまく選ぶことで、食べる可能性のあるビーンズのおいしさの最小値を最大化してください。
制約
- 1 \leq N \leq 2 \times 10^{5}
- 1 \leq A_i \leq 10^{9}
- 1 \leq C_i \leq 10^{9}
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N A_1 C_1 A_2 C_2 \vdots A_N C_N
出力
食べる可能性のあるビーンズのおいしさの最小値の最大値を整数として出力せよ。
入力例 1
4 100 1 20 5 30 5 40 1
出力例 1
40
同じ色のビーンズは互いに区別がつかないことに注意してください。
選ぶことができる色は 色 1 と 色 5 です。
- 色 1 のビーンズは 2 種類あり、美味しさはそれぞれ 100, 40 です。よって、色 1 を選んだときのおいしさの最小値は 40 です。
- 色 5 のビーンズは 2 種類あり、美味しさはそれぞれ 20, 30 です。よって、色 5 を選んだときのおいしさの最小値は 20 です。
おいしさの最小値を最大化するには 色 1 を選べばよいため、そのときの最小値である 40 を出力します。
入力例 2
10 68 3 17 2 99 2 92 4 82 4 10 3 100 2 78 1 3 1 35 4
出力例 2
35
Score: 250 points
Problem Statement
There are N types of beans, one bean of each type. The i-th type of bean has a deliciousness of A_i and a color of C_i. The beans are mixed and can only be distinguished by color.
You will choose one color of beans and eat one bean of that color. By selecting the optimal color, maximize the minimum possible deliciousness of the bean you eat.
Constraints
- 1 \leq N \leq 2 \times 10^{5}
- 1 \leq A_i \leq 10^{9}
- 1 \leq C_i \leq 10^{9}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 C_1 A_2 C_2 \vdots A_N C_N
Output
Print as an integer the maximum value of the minimum possible deliciousness of the bean you eat.
Sample Input 1
4 100 1 20 5 30 5 40 1
Sample Output 1
40
Note that beans of the same color cannot be distinguished from each other.
You can choose color 1 or color 5.
- There are two types of beans of color 1, with deliciousness of 100 and 40. Thus, the minimum deliciousness when choosing color 1 is 40.
- There are two types of beans of color 5, with deliciousness of 20 and 30. Thus, the minimum deliciousness when choosing color 5 is 20.
To maximize the minimum deliciousness, you should choose color 1, so print the minimum deliciousness in that case: 40.
Sample Input 2
10 68 3 17 2 99 2 92 4 82 4 10 3 100 2 78 1 3 1 35 4
Sample Output 2
35
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
2 以上の整数 K が与えられます。
正の整数 N であって、N! が K の倍数となるようなもののうち最小のものを求めてください。
ただし、N! は N の階乗を表し、問題の制約下で、そのような N が必ず存在することが証明できます。
制約
- 2\leq K\leq 10^{12}
- K は整数
入力
入力は以下の形式で標準入力から与えられる。
K
出力
N! が K の倍数となるような最小の正整数 N を出力せよ。
入力例 1
30
出力例 1
5
- 1!=1
- 2!=2\times 1=2
- 3!=3\times 2\times 1=6
- 4!=4\times 3\times 2\times 1=24
- 5!=5\times 4\times 3\times 2\times 1=120
より、N! が 30 の倍数となる最小の正整数 N は 5 です。よって、5 を出力します。
入力例 2
123456789011
出力例 2
123456789011
入力例 3
280
出力例 3
7
Score : 400 points
Problem Statement
You are given an integer K greater than or equal to 2.
Find the minimum positive integer N such that N! is a multiple of K.
Here, N! denotes the factorial of N. Under the Constraints of this problem, we can prove that such an N always exists.
Constraints
- 2\leq K\leq 10^{12}
- K is an integer.
Input
The input is given from Standard Input in the following format:
K
Output
Print the minimum positive integer N such that N! is a multiple of K.
Sample Input 1
30
Sample Output 1
5
- 1!=1
- 2!=2\times 1=2
- 3!=3\times 2\times 1=6
- 4!=4\times 3\times 2\times 1=24
- 5!=5\times 4\times 3\times 2\times 1=120
Therefore, 5 is the minimum positive integer N such that N! is a multiple of 30. Thus, 5 should be printed.
Sample Input 2
123456789011
Sample Output 2
123456789011
Sample Input 3
280
Sample Output 3
7
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
空の列 A があります。クエリが Q 個与えられるので、与えられた順番に処理してください。
クエリは次の 3 種類のいずれかです。
1 x
: A の最後尾に x を追加する。2
: A の最初の要素を出力する。その後、その要素を削除する。このクエリが与えられるとき、A は空でないことが保証される。3
: A を昇順にソートする。
制約
- 1 \leq Q \leq 2 \times 10^5
- 0 \leq x \leq 10^9
- クエリ
2
が与えられるとき、A は空でない。 - 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
Q \mathrm{query} 1 \mathrm{query} 2 \vdots \mathrm{query} Q
i 番目のクエリ \mathrm{query} i では、まずクエリの種類 c_i( 1, 2, 3 のいずれか)が与えられる。 c_i = 1 の場合はさらに整数 x が追加で与えられる。
すなわち、各クエリは以下に示す 3 つの形式のいずれかである。
1 x
2
3
出力
c_i = 2 を満たすクエリの回数を q として q 行出力せよ。
j (1 \leq j \leq q) 行目では j 番目のそのようなクエリに対する答えを出力せよ。
入力例 1
8 1 4 1 3 1 2 1 1 3 2 1 0 2
出力例 1
1 2
入力例 1 において、 i 番目のクエリを処理した後の A の状態を i 行目に示すと以下のようになります。
- (4)
- (4, 3)
- (4, 3, 2)
- (4, 3, 2, 1)
- (1, 2, 3, 4)
- (2, 3, 4)
- (2, 3, 4, 0)
- (3, 4, 0)
入力例 2
9 1 5 1 5 1 3 2 3 2 1 6 3 2
出力例 2
5 3 5
入力例 2 において、 i 番目のクエリを処理した後の A の状態を i 行目に示すと以下のようになります。
- (5)
- (5, 5)
- (5, 5, 3)
- (5, 3)
- (3, 5)
- (5)
- (5, 6)
- (5, 6)
- (6)
Score : 500 points
Problem Statement
We have an empty sequence A. You will be given Q queries, which should be processed in the order they are given. Each query is of one of the three kinds below:
1 x
: Append x to the end of A.2
: Print the element at the beginning of A. Then, delete that element. It is guaranteed that A will not empty when this query is given.3
: Sort A in ascending order.
Constraints
- 1 \leq Q \leq 2 \times 10^5
- 0 \leq x \leq 10^9
- A will not be empty when a query
2
is given. - All values in input are integers.
Input
Input is given from Standard Input in the following format:
Q \mathrm{query} 1 \mathrm{query} 2 \vdots \mathrm{query} Q
The i-th query, \mathrm{query} i, begins with the kind of query c_i (1, 2, or 3). If c_i = 1, the line additionally has an integer x.
In other words, each query is in one of the three formats below.
1 x
2
3
Output
Print q lines, where q is the number of queries with c_i = 2.
The j-th line (1 \leq j \leq q) should contain the response for the j-th such query.
Sample Input 1
8 1 4 1 3 1 2 1 1 3 2 1 0 2
Sample Output 1
1 2
The i-th line below shows the contents of A after the i-th query is processed in Sample Input 1.
- (4)
- (4, 3)
- (4, 3, 2)
- (4, 3, 2, 1)
- (1, 2, 3, 4)
- (2, 3, 4)
- (2, 3, 4, 0)
- (3, 4, 0)
Sample Input 2
9 1 5 1 5 1 3 2 3 2 1 6 3 2
Sample Output 2
5 3 5
The i-th line below shows the contents of A after the i-th query is processed in Sample Input 2.
- (5)
- (5, 5)
- (5, 5, 3)
- (5, 3)
- (3, 5)
- (5)
- (5, 6)
- (5, 6)
- (6)
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
高橋君は N 本の砂糖水を、青木君は M 本の砂糖水を持っています。
高橋君の持っている i 番目の砂糖水は砂糖 A_i グラムと水 B_i グラムからなります。
青木君の持っている i 番目の砂糖水は砂糖 C_i グラムと水 D_i グラムからなります。
2 人の持つ砂糖水をそれぞれ 1 本ずつ選んで混ぜる方法は NM 通りあります。そのような方法でできる砂糖水の中で、濃度が高い方から K 番目の砂糖水の濃度が何 \% であるかを求めてください。
ここで、砂糖 x グラムと水 y グラムからなる砂糖水の濃度は \dfrac{100x}{x+y}\ \% です。また、砂糖が溶け残ることは考えないものとします。
制約
- 1 \leq N, M \leq 5 \times 10^4
- 1 \leq K \leq N \times M
- 1 \leq A_i, B_i, C_i, D_i \leq 10^5
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M K A_1 B_1 A_2 B_2 \vdots A_N B_N C_1 D_1 C_2 D_2 \vdots C_M D_M
出力
濃度が高い方から K 番目の砂糖水の濃度をパーセントで出力せよ。
なお、真の値との絶対誤差または相対誤差が 10^{−9} 以下であれば正解として扱われる。
入力例 1
3 1 1 1 2 4 1 1 4 1 4
出力例 1
50.000000000000000
以下では高橋君が持っている i 番目の砂糖水と青木君が持っている j 番目の砂糖水を混ぜてできる砂糖水を (i, j) と表します。
あり得る砂糖水の混ぜ方とその濃度を列挙すると以下のようになります。
- (1, 1) : 100 \times \frac{1 + 1}{(1 + 1) + (2 + 4)} = 25 \%
- (2, 1) : 100 \times \frac{1 + 4}{(4 + 1) + (1 + 4)} = 50 \%
- (3, 1) : 100 \times \frac{1 + 1}{(1 + 1) + (4 + 4)} = 20 \%
この中で濃度が高い方から 1 番目の砂糖水は (2, 1) で、濃度は 50 \% です。
入力例 2
2 2 2 6 4 10 1 5 8 9 6
出力例 2
62.500000000000000
入力例 3
4 5 10 5 4 1 6 7 4 9 8 2 2 5 6 6 7 5 3 8 1
出力例 3
54.166666666666664
Score : 500 points
Problem Statement
Takahashi and Aoki have N and M bottles of sugar water, respectively.
Takahashi's i-th sugar water is composed of A_i grams of sugar and B_i grams of water.
Aoki's i-th sugar water is composed of C_i grams of sugar and D_i grams of water.
There are NM ways to choose one from Takahashi's sugar waters and one from Aoki's and mix them. Among the NM sugar waters that can be obtained in this way, find the concentration of sugar in the sugar water with the K-th highest concentration of sugar.
Here, the concentration of sugar in sugar water composed of x grams of sugar and y grams of water is \dfrac{100x}{x+y} percent. We will ignore saturation.
Constraints
- 1 \leq N, M \leq 5 \times 10^4
- 1 \leq K \leq N \times M
- 1 \leq A_i, B_i, C_i, D_i \leq 10^5
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M K A_1 B_1 A_2 B_2 \vdots A_N B_N C_1 D_1 C_2 D_2 \vdots C_M D_M
Output
Print the concentration of sugar in the sugar water with the K-th highest concentration of sugar in percent.
Your output will be considered correct if the absolute or relative error from the true value is at most 10^{−9}.
Sample Input 1
3 1 1 1 2 4 1 1 4 1 4
Sample Output 1
50.000000000000000
Let (i, j) denote the sugar water obtained by mixing Takahashi's i-th sugar water and Aoki's j-th.
Below are the sugar waters that can be obtained and their concentrations of sugar.
- (1, 1) : 100 \times \frac{1 + 1}{(1 + 1) + (2 + 4)} = 25 \%
- (2, 1) : 100 \times \frac{1 + 4}{(4 + 1) + (1 + 4)} = 50 \%
- (3, 1) : 100 \times \frac{1 + 1}{(1 + 1) + (4 + 4)} = 20 \%
Among them, the sugar water with the highest concentration of sugar is (2, 1), with a concentration of 50 percent.
Sample Input 2
2 2 2 6 4 10 1 5 8 9 6
Sample Output 2
62.500000000000000
Sample Input 3
4 5 10 5 4 1 6 7 4 9 8 2 2 5 6 6 7 5 3 8 1
Sample Output 3
54.166666666666664