Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
りんご市場に N 人の売り手と M 人の買い手がいます。
i 番目の売り手は、A_i 円以上でならりんごを売ってもよいと考えています。
i 番目の買い手は、B_i 円以下でならりんごを買ってもよいと考えています。
次の条件を満たすような最小の整数 X を求めてください。
条件:りんごを X 円で売ってもよいと考える売り手の人数が、りんごを X 円で買ってもよいと考える買い手の人数以上である。
制約
- 1 \leq N,M \leq 2\times 10^5
- 1\leq A_i,B_i \leq 10^9
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 \ldots A_N B_1 \ldots B_M
出力
答えを出力せよ。
入力例 1
3 4 110 90 120 100 80 120 10000
出力例 1
110
りんごを 110 円で売ってもよいと考える売り手は 1,2 番目の 2 人であり、りんごを 110 円で買ってもよいと考える買い手は 3,4 番目の 2 人であるため、110 は条件を満たします。
110 未満の整数が条件を満たすことはないため、これが答えです。
入力例 2
5 2 100000 100000 100000 100000 100000 100 200
出力例 2
201
入力例 3
3 2 100 100 100 80 120
出力例 3
100
Score : 300 points
Problem Statement
There are N sellers and M buyers in an apple market.
The i-th seller may sell an apple for A_i yen or more (yen is the currency in Japan).
The i-th buyer may buy an apple for B_i yen or less.
Find the minimum integer X that satisfies the following condition.
Condition: The number of people who may sell an apple for X yen is greater than or equal to the number of people who may buy an apple for X yen.
Constraints
- 1 \leq N,M \leq 2\times 10^5
- 1\leq A_i,B_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 \ldots A_N B_1 \ldots B_M
Output
Print the answer.
Sample Input 1
3 4 110 90 120 100 80 120 10000
Sample Output 1
110
Two sellers, the 1-st and 2-nd, may sell an apple for 110 yen; two buyers, the 3-rd and 4-th, may buy an apple for 110 yen. Thus, 110 satisfies the condition.
Since an integer less than 110 does not satisfy the condition, this is the answer.
Sample Input 2
5 2 100000 100000 100000 100000 100000 100 200
Sample Output 2
201
Sample Input 3
3 2 100 100 100 80 120
Sample Output 3
100
Time Limit: 4 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 枚の靴下があります。i 枚目の靴下の色は A_i です。
あなたは以下の操作をできるだけ多い回数行いたいです。最大で何回行うことができますか?
- まだペアになっていない靴下の中から同じ色の靴下を 2 枚選んでペアにする。
制約
- 1\leq N \leq 5\times 10^5
- 1\leq A_i \leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \dots A_N
出力
答えを整数として出力せよ。
入力例 1
6 4 1 7 4 1 4
出力例 1
2
以下のようにして、2 回の操作を行うことができます。
- 色が 1 である靴下を 2 枚選んでペアにする。
- 色が 4 である靴下を 2 枚選んでペアにする。
このとき、色が 4 である靴下と 7 である靴下が 1 枚ずつ残るため、これ以上操作はできません。 また、どのように操作をしても 3 回以上操作を行うことはできないため、2 を出力します。
入力例 2
1 158260522
出力例 2
0
入力例 3
10 295 2 29 295 29 2 29 295 2 29
出力例 3
4
Score : 300 points
Problem Statement
You have N socks. The color of the i-th sock is A_i.
You want to perform the following operation as many times as possible. How many times can it be performed at most?
- Choose two same-colored socks that are not paired yet, and pair them.
Constraints
- 1\leq N \leq 5\times 10^5
- 1\leq A_i \leq 10^9
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \dots A_N
Output
Print an integer representing the answer.
Sample Input 1
6 4 1 7 4 1 4
Sample Output 1
2
You can do the operation twice as follows.
- Choose two socks with the color 1 and pair them.
- Choose two socks with the color 4 and pair them.
Then, you will be left with one sock with the color 4 and another with the color 7, so you can no longer do the operation. There is no way to do the operation three or more times, so you should print 2.
Sample Input 2
1 158260522
Sample Output 2
0
Sample Input 3
10 295 2 29 295 29 2 29 295 2 29
Sample Output 3
4
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
整数 N が与えられます。以下の条件を満たす N 以下の正整数の組 (i,j) の個数を求めてください。
- i \times j は平方数である。
制約
- 1 \le N \le 2 \times 10^5
- N は整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
4
出力例 1
6
(1,1),(1,4),(2,2),(3,3),(4,1),(4,4) の 6 個が条件を満たします。
(2,3) は 2 \times 3 =6 が平方数でないため条件を満たしません。
入力例 2
254
出力例 2
896
Score : 400 points
Problem Statement
You are given an integer N. Find the number of pairs (i,j) of positive integers at most N that satisfy the following condition:
- i \times j is a square number.
Constraints
- 1 \le N \le 2 \times 10^5
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
4
Sample Output 1
6
The six pairs (1,1),(1,4),(2,2),(3,3),(4,1),(4,4) satisfy the condition.
On the other hand, (2,3) does not, since 2 \times 3 =6 is not a square number.
Sample Input 2
254
Sample Output 2
896
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
二次元平面上の第一象限上に N 個のフの字があります。
i\ (1 \leq i \leq N) 個目のフの字は、(x_i-1,y_i) と (x_i,y_i) を結ぶ線分と (x_i,y_i-1) と (x_i,y_i) を結ぶ線分の 2 つを組み合わせた図形です。
あなたは、N 個のフの字から 0 個以上を選び、削除することができます。
適切に削除するフの字を選んだとき、原点から全体が見えるフの字の個数は最大でいくつになりますか?
ここで、原点からあるフの字(便宜上 i 個目のフの字とする)の全体が見える必要十分条件は、以下の通りです。
- 原点、(x_i-1,y_i)、(x_i,y_i)、(x_i,y_i-1) の 4 点を頂点とする四角形の内部(境界を除く)と他のフの字が共通部分を持たない。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq x_i,y_i \leq 10^9
- (x_i,y_i) \neq (x_j,y_j)\ (i \neq j)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N x_1 y_1 x_2 y_2 \hspace{0.45cm}\vdots x_N y_N
出力
原点から全体が見えるフの字の個数の最大値を出力せよ。
入力例 1
3 1 1 2 1 1 2
出力例 1
2
1 個目のフの字を削除したとき原点からは 2 個目のフの字と 3 個目のフの字の 2 つが見えるようになり、これが最大です。
1 つのフの字も削除しない場合、原点からは 1 個目のフの字のみしか見えません。
入力例 2
10 414598724 87552841 252911401 309688555 623249116 421714323 605059493 227199170 410455266 373748111 861647548 916369023 527772558 682124751 356101507 249887028 292258775 110762985 850583108 796044319
出力例 2
10
すべてのフの字を削除せずに残すのが最善です。
Score : 500 points
Problem Statement
There are N 7's drawn in the first quadrant of a plane.
The i-th 7 is a figure composed of a segment connecting (x_i-1,y_i) and (x_i,y_i), and a segment connecting (x_i,y_i-1) and (x_i,y_i).
You can choose zero or more from the N 7's and delete them.
What is the maximum possible number of 7's that are wholly visible from the origin after the optimal deletion?
Here, the i-th 7 is wholly visible from the origin if and only if:
- the interior (excluding borders) of the quadrilateral whose vertices are the origin, (x_i-1,y_i), (x_i,y_i), (x_i,y_i-1) does not intersect with the other 7's.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq x_i,y_i \leq 10^9
- (x_i,y_i) \neq (x_j,y_j)\ (i \neq j)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N x_1 y_1 x_2 y_2 \hspace{0.45cm}\vdots x_N y_N
Output
Print the maximum possible number of 7's that are wholly visible from the origin.
Sample Input 1
3 1 1 2 1 1 2
Sample Output 1
2
If the first 7 is deleted, the other two 7's ― the second and third ones ― will be wholly visible from the origin, which is optimal.
If no 7's are deleted, only the first 7 is wholly visible from the origin.
Sample Input 2
10 414598724 87552841 252911401 309688555 623249116 421714323 605059493 227199170 410455266 373748111 861647548 916369023 527772558 682124751 356101507 249887028 292258775 110762985 850583108 796044319
Sample Output 2
10
It is best to keep all 7's.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
長さ N の数列 A = (A_1, \dots, A_N), B = (B_1, \dots, B_N) が与えられます。\{1,2,\ldots,N\} の空でない部分集合 S であって、以下の条件を満たすものの個数を数えてください。
- \max_{i \in S} A_i \geq \sum_{i \in S} B_i
なお、答えは非常に大きくなることがあるため、998244353 で割ったあまりを出力してください。
制約
- 1 \leq N \leq 5000
- 1 \leq A_i,B_i \leq 5000
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N
出力
問題文中の条件を満たす S の個数を 998244353 で割ったあまりを出力せよ。
入力例 1
2 3 1 1 2
出力例 1
2
\{1,2,\ldots,N\} の空でない部分集合としてあり得るものは、\{1\}, \{2\}, \{1,2\} の 3 通りです。
- S=\{1\} のとき \max_{i \in S} A_i=3, \sum_{i \in S} B_i=1
- S=\{2\} のとき \max_{i \in S} A_i=1, \sum_{i \in S} B_i=2
- S=\{1,2\} のとき \max_{i \in S} A_i=3, \sum_{i \in S} B_i=3
であるため、問題文中の条件、即ち \max_{i \in S} A_i \geq \sum_{i \in S} B_i を満たす S は \{1\} と \{1,2\} の 2 通りです。
入力例 2
2 1 1 2 2
出力例 2
0
条件を満たす S が存在しない場合もあります。
入力例 3
20 1937 3980 2689 1208 3640 1979 581 2271 4229 3948 3708 1522 4161 4661 3797 96 3388 3395 2920 2247 4485 2580 174 1156 3770 3396 3558 3500 3494 479 269 3383 1230 1711 3545 3919 134 475 3796 1017
出力例 3
476
Score : 500 points
Problem Statement
Given are sequences of N integers each: A = (A_1, \dots, A_N) and B = (B_1, \dots, B_N). Find the number of non-empty subsets S of \{1,2,\ldots,N\} that satisfy the following condition:
- \max_{i \in S} A_i \geq \sum_{i \in S} B_i.
Since the count can be enormous, print it modulo 998244353.
Constraints
- 1 \leq N \leq 5000
- 1 \leq A_i,B_i \leq 5000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N
Output
Print the number of subsets S that satisfy the condition in the Problem Statement, modulo 998244353.
Sample Input 1
2 3 1 1 2
Sample Output 1
2
\{1,2,\ldots,N\} has three subsets: \{1\}, \{2\}, and \{1,2\}.
- For S=\{1\}, we have \max_{i \in S} A_i=3 and \sum_{i \in S} B_i=1.
- For S=\{2\}, we have \max_{i \in S} A_i=1 and \sum_{i \in S} B_i=2.
- For S=\{1,2\}, we have \max_{i \in S} A_i=3 and \sum_{i \in S} B_i=3.
Thus, the condition \max_{i \in S} A_i \geq \sum_{i \in S} B_i is satisfied by two subsets: \{1\} and \{1,2\}.
Sample Input 2
2 1 1 2 2
Sample Output 2
0
There may be no subsets that satisfy the condition.
Sample Input 3
20 1937 3980 2689 1208 3640 1979 581 2271 4229 3948 3708 1522 4161 4661 3797 96 3388 3395 2920 2247 4485 2580 174 1156 3770 3396 3558 3500 3494 479 269 3383 1230 1711 3545 3919 134 475 3796 1017
Sample Output 3
476