Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
キーエンス本社に勤務する人数が増えてきたので、本社に存在する部署を 2 つのグループに分け、昼休みの時間帯を分けることにしました。
キーエンス本社には N 個の部署が存在し、i 番目 (1\leq i\leq N) の部署に所属する人数は K_i 人です。
それぞれの部署をグループ A, B のいずれか一方に割り当て、グループごとに同時に昼休みをとり、
かつグループ A, B の昼休みの時間が重ならないようにしたとき、同時に昼休みをとる最大人数としてあり得る最小の値を求めてください。
すなわち、グループ A に割り当てられた部署に所属する人数の合計とグループ B に割り当てられた部署に所属する人数の合計
のうち大きい方の値としてあり得る最小の値を求めてください。
制約
- 2\leq N \leq 20
- 1\leq K_i \leq 10^8
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K_1 K_2 \ldots K_N
出力
同時に昼休みを取る最大人数としてあり得る最小の値を出力せよ。
入力例 1
5 2 3 5 10 12
出力例 1
17
1,2,5 番目の部署をグループ A に、3,4 番目の部署をグループ B に割り当てたとき、 グループ A に割り当てられた部署に所属する人数の合計は 2+3+12=17 、 グループ B に割り当てられた部署に所属する人数の合計は 5+10=15 となり、 このとき同時に昼休みを取る最大人数は 17 となります。
一方で、グループ A,B それぞれに割り当てられた部署に所属する人数の合計がいずれも 16 以下になるように 部署を割り当てることはできないため、17 を出力します。
入力例 2
2 1 1
出力例 2
1
同一人数の部署が複数存在する可能性もあります。
入力例 3
6 22 25 26 45 22 31
出力例 3
89
例えば、1,4,5 番目の部署をグループ A に、2,3,6 番目の部署をグループ B に割り当てたとき同時に昼休みを取る最大人数は 89 となります。
Score : 300 points
Problem Statement
As KEYENCE headquarters have more and more workers, they decided to divide the departments in the headquarters into two groups and stagger their lunch breaks.
KEYENCE headquarters have N departments, and the number of people in the i-th department (1\leq i\leq N) is K_i.
When assigning each department to Group A or Group B, having each group take lunch breaks at the same time, and ensuring that the lunch break times of Group A and Group B do not overlap, find the minimum possible value of the maximum number of people taking a lunch break at the same time.
In other words, find the minimum possible value of the larger of the following: the total number of people in departments assigned to Group A, and the total number of people in departments assigned to Group B.
Constraints
- 2 \leq N \leq 20
- 1 \leq K_i \leq 10^8
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K_1 K_2 \ldots K_N
Output
Print the minimum possible value of the maximum number of people taking a lunch break at the same time.
Sample Input 1
5 2 3 5 10 12
Sample Output 1
17
When assigning departments 1, 2, and 5 to Group A, and departments 3 and 4 to Group B, Group A has a total of 2+3+12=17 people, and Group B has a total of 5+10=15 people. Thus, the maximum number of people taking a lunch break at the same time is 17.
It is impossible to assign the departments so that both groups have 16 or fewer people, so print 17.
Sample Input 2
2 1 1
Sample Output 2
1
Multiple departments may have the same number of people.
Sample Input 3
6 22 25 26 45 22 31
Sample Output 3
89
For example, when assigning departments 1, 4, and 5 to Group A, and departments 2, 3, and 6 to Group B, the maximum number of people taking a lunch break at the same time is 89.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
二次元平面の点 (0,0) に高橋君がいます。初め、高橋君の体力は H です。また、二次元平面には M 個の体力を回復するアイテムがあり、i 個目のアイテムは点 (x_i,y_i) に置いてあります。
高橋君は、これから N 回の移動をします。i 回目の移動は以下の方法で行われます。
-
今高橋君がいる点を (x,y) とする。体力を 1 消費し、S の i 番目の文字 S_i に応じて以下の点に移動する。
- S_i が
Rのとき: (x+1,y) - S_i が
Lのとき: (x-1,y) - S_i が
Uのとき: (x,y+1) - S_i が
Dのとき: (x,y-1)
- S_i が
-
高橋君の体力が負になった場合、高橋君は倒れてしまい、移動をやめる。そうでない場合、移動した点にアイテムがあり、かつ高橋君の体力が K 未満ならば、移動した点に置かれたアイテムを消費し、高橋君の体力が K になる。
高橋君が一度も倒れることなく N 回の移動を行えるか判定してください。
制約
- 1\leq N,M,H,K\leq 2\times 10^5
- S は
R,L,U,Dからなる長さ N の文字列 - |x_i|,|y_i| \leq 2\times 10^5
- (x_i,y_i) は互いに異なる
- S 以外の入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M H K S x_1 y_1 \vdots x_M y_M
出力
高橋君が一度も倒れることなく N 回の移動を行える場合 Yes を、そうでない場合 No を出力せよ。
入力例 1
4 2 3 1 RUDL -1 -1 1 0
出力例 1
Yes
初め高橋君の体力は 3 です。以下で移動を説明します。
-
1 回目の移動: S_i が
Rなので点 (1,0) に移動する。高橋君の体力は 2 に減る。点 (1,0) にはアイテムが置いてあるが、高橋君の体力は K=1 以上なのでアイテムは消費されない。 -
2 回目の移動: S_i が
Uなので点 (1,1) に移動する。高橋君の体力は 1 に減る。 -
3 回目の移動: S_i が
Dなので点 (1,0) に移動する。高橋君の体力は 0 に減る。点 (1,0) にはアイテムが置いてあり、体力は K=1 未満なのでアイテムを消費し、体力が 1 になる。 -
4 回目の移動: S_i が
Lなので点 (0,0) に移動する。高橋君の体力は 0 に減る。
以上より、高橋君は倒れずに 4 回の移動を行えるので、Yes を出力してください。体力は 0 になってもいいことに注意してください。
入力例 2
5 2 1 5 LDRLD 0 0 -1 -1
出力例 2
No
初め高橋君の体力は 1 です。以下で移動を説明します。
-
1 回目の移動: S_i が
Lなので点 (-1,0) に移動する。高橋君の体力は 0 に減る。 -
2 回目の移動: S_i が
Dなので点 (-1,-1) に移動する。高橋君の体力は -1 に減る。体力が -1 になってしまったので、高橋君は倒れてしまい、移動をやめる。
以上より、高橋君は倒れてしまうので、No を出力してください。
高橋君がはじめいる点 (0,0) にはアイテムが置いてありますが、移動後にアイテムは消費されるので、1 回目の移動前にアイテムを消費しないことに注意してください。
Score : 300 points
Problem Statement
On a two-dimensional plane, Takahashi is initially at point (0, 0), and his initial health is H. M items to recover health are placed on the plane; the i-th of them is placed at (x_i,y_i).
Takahashi will make N moves. The i-th move is as follows.
-
Let (x,y) be his current coordinates. He consumes a health of 1 to move to the following point, depending on S_i, the i-th character of S:
- (x+1,y) if S_i is
R; - (x-1,y) if S_i is
L; - (x,y+1) if S_i is
U; - (x,y-1) if S_i is
D.
- (x+1,y) if S_i is
-
If Takahashi's health has become negative, he collapses and stops moving. Otherwise, if an item is placed at the point he has moved to, and his health is strictly less than K, then he consumes the item there to make his health K.
Determine if Takahashi can complete the N moves without being stunned.
Constraints
- 1\leq N,M,H,K\leq 2\times 10^5
- S is a string of length N consisting of
R,L,U, andD. - |x_i|,|y_i| \leq 2\times 10^5
- (x_i, y_i) are pairwise distinct.
- All values in the input are integers, except for S.
Input
The input is given from Standard Input in the following format:
N M H K S x_1 y_1 \vdots x_M y_M
Output
Print Yes if he can complete the N moves without being stunned; print No otherwise.
Sample Input 1
4 2 3 1 RUDL -1 -1 1 0
Sample Output 1
Yes
Initially, Takahashi's health is 3. We describe the moves below.
-
1-st move: S_i is
R, so he moves to point (1,0). His health reduces to 2. Although an item is placed at point (1,0), he do not consume it because his health is no less than K=1. -
2-nd move: S_i is
U, so he moves to point (1,1). His health reduces to 1. -
3-rd move: S_i is
D, so he moves to point (1,0). His health reduces to 0. An item is placed at point (1,0), and his health is less than K=1, so he consumes the item to make his health 1. -
4-th move: S_i is
L, so he moves to point (0,0). His health reduces to 0.
Thus, he can make the 4 moves without collapsing, so Yes should be printed. Note that the health may reach 0.
Sample Input 2
5 2 1 5 LDRLD 0 0 -1 -1
Sample Output 2
No
Initially, Takahashi's health is 1. We describe the moves below.
-
1-st move: S_i is
L, so he moves to point (-1,0). His health reduces to 0. -
2-nd move: S_i is
D, so he moves to point (-1,-1). His health reduces to -1. Now that the health is -1, he collapses and stops moving.
Thus, he will be stunned, so No should be printed.
Note that although there is an item at his initial point (0,0), he does not consume it before the 1-st move, because items are only consumed after a move.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
N 種類の弁当が、それぞれ 1 個ずつ売られています。
i = 1, 2, \ldots, N について、i 種類目の弁当には A_i 個のたこ焼きと B_i 個のたい焼きが入っています。
高橋君は、 X 個以上のたこ焼きと Y 個以上のたい焼きを食べたいです。
高橋君がいくつかの弁当を選んで買うことで、 X 個以上のたこ焼きと Y 個以上のたい焼きを手に入れることが可能かどうか判定して下さい。また、可能な場合はそのために高橋君が購入しなければならない弁当の個数の最小値を求めて下さい。
各種類の弁当は 1 個しか売られていないため、同じ種類の弁当を 2 個以上購入することは出来ないことに注意して下さい。
制約
- 1 \leq N \leq 300
- 1 \leq X, Y \leq 300
- 1 \leq A_i, B_i \leq 300
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N X Y A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
高橋君が X 個以上のたこ焼きと Y 個以上のたい焼きを手に入れることが不可能な場合は -1 を出力し、 可能な場合はそのために高橋君が購入しなければならない弁当の個数の最小値を出力せよ。
入力例 1
3 5 6 2 1 3 4 2 3
出力例 1
2
高橋君は、5 個以上のたこ焼きと 6 個以上のたい焼きを食べたいです。
高橋君は 2 種類目の弁当と 3 種類目の弁当を買うことで、
たこ焼きを 3 + 2 = 5 個、たい焼きを 4 + 3 = 7 個手に入れることができます。
入力例 2
3 8 8 3 4 2 3 2 1
出力例 2
-1
高橋君がたとえすべての弁当を買ったとしても、高橋君は 8 個以上のたこ焼きと 8 個以上のたい焼きを手に入れることが出来ません。
よって、-1 を出力します。
Score : 400 points
Problem Statement
A shop sells N kinds of lunchboxes, one for each kind.
For each i = 1, 2, \ldots, N, the i-th kind of lunchbox contains A_i takoyaki (octopus balls) and B_i taiyaki (fish-shaped cakes).
Takahashi wants to eat X or more takoyaki and Y or more taiyaki.
Determine whether it is possible to buy some number of lunchboxes to get at least X takoyaki and at least Y taiyaki. If it is possible, find the minimum number of lunchboxes that Takahashi must buy to get them.
Note that just one lunchbox is in stock for each kind; you cannot buy two or more lunchboxes of the same kind.
Constraints
- 1 \leq N \leq 300
- 1 \leq X, Y \leq 300
- 1 \leq A_i, B_i \leq 300
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X Y A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
If Takahashi cannot get at least X takoyaki and at least Y taiyaki, print -1; otherwise, print the minimum number of lunchboxes that he must buy to get them.
Sample Input 1
3 5 6 2 1 3 4 2 3
Sample Output 1
2
He wants to eat 5 or more takoyaki and 6 or more taiyaki.
Buying the second and third lunchboxes will get him 3 + 2 = 5 taiyaki and 4 + 3 = 7 taiyaki.
Sample Input 2
3 8 8 3 4 2 3 2 1
Sample Output 2
-1
Even if he is to buy every lunchbox, it is impossible to get at least 8 takoyaki and at least 8 taiyaki.
Thus, print -1.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
整数 M および N 個の整数の組 (A_1, B_1), (A_2, B_2), \dots, (A_N, B_N) が与えられます。
すべての i について 1 \leq A_i \lt B_i \leq M が成り立っています。
次の条件を満たす数列 S を良い数列と呼びます。
- S は数列 (1,2,3,..., M) の連続部分列である。
- すべての i について S は A_i, B_i の少なくとも一方を含んでいる。
長さ k の良い数列としてあり得るものの個数を f(k) とします。
f(1), f(2), \dots, f(M) を列挙してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 2 \leq M \leq 2 \times 10^5
- 1 \leq A_i \lt B_i \leq M
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 A_2 B_2 \vdots A_N B_N
出力
答えを以下の形式で出力せよ。
f(1) f(2) \dots f(M)
入力例 1
3 5 1 3 1 4 2 5
出力例 1
0 1 3 2 1
良い数列としてあり得るものを列挙すると次のようになります。
- (1,2)
- (1,2,3)
- (2,3,4)
- (3,4,5)
- (1,2,3,4)
- (2,3,4,5)
- (1,2,3,4,5)
入力例 2
1 2 1 2
出力例 2
2 1
入力例 3
5 9 1 5 1 7 5 6 5 8 2 6
出力例 3
0 0 1 2 4 4 3 2 1
Score : 500 points
Problem Statement
You are given an integer M and N pairs of integers (A_1, B_1), (A_2, B_2), \dots, (A_N, B_N).
For all i, it holds that 1 \leq A_i \lt B_i \leq M.
A sequence S is said to be a good sequence if the following conditions are satisfied:
- S is a contiguous subsequence of the sequence (1,2,3,..., M).
- For all i, S contains at least one of A_i and B_i.
Let f(k) be the number of possible good sequences of length k.
Enumerate f(1), f(2), \dots, f(M).
Constraints
- 1 \leq N \leq 2 \times 10^5
- 2 \leq M \leq 2 \times 10^5
- 1 \leq A_i \lt B_i \leq M
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 B_1 A_2 B_2 \vdots A_N B_N
Output
Print the answers in the following format:
f(1) f(2) \dots f(M)
Sample Input 1
3 5 1 3 1 4 2 5
Sample Output 1
0 1 3 2 1
Here is the list of all possible good sequences.
- (1,2)
- (1,2,3)
- (2,3,4)
- (3,4,5)
- (1,2,3,4)
- (2,3,4,5)
- (1,2,3,4,5)
Sample Input 2
1 2 1 2
Sample Output 2
2 1
Sample Input 3
5 9 1 5 1 7 5 6 5 8 2 6
Sample Output 3
0 0 1 2 4 4 3 2 1
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
xy 平面上に N 個の点 1,2,\dots,N があります。このうち点 i は座標 (X_i,Y_i) にあります。
あなたは、以下の操作を 0 回以上 K 回以下行うことができます。
- まず、 N 点の中からひとつを選択する。選ばれた点を k とし、この点が現在 (x,y) にあるものとする。
- 次に、以下の 4 つからひとつを選択し、実行する。
- 点 k を x 軸沿いに +1 だけ移動させる。点 k の座標は (x+1,y) となる。
- 点 k を x 軸沿いに -1 だけ移動させる。点 k の座標は (x-1,y) となる。
- 点 k を y 軸沿いに +1 だけ移動させる。点 k の座標は (x,y+1) となる。
- 点 k を y 軸沿いに -1 だけ移動させる。点 k の座標は (x,y-1) となる。
- 複数の点を同じ座標に存在させることも許されます。また、入力で複数の点が同じ座標に存在しうることに注意してください。
全ての操作が終わった後、 N 個全ての点を内部または周上に包含する、各辺が x 軸または y 軸に平行な正方形をひとつ書き込みます。
このとき、書き込む正方形の一辺の長さとしてありうる最小の値を求めてください。全ての点が常に格子点にあることから、この値は整数であることが示せます。
特に、全ての点を同じ座標に存在させられる時、答えは 0 であるものとします。
制約
- 入力は全て整数
- 1 \le N \le 2 \times 10^5
- 0 \le K \le 4 \times 10^{14}
- 0 \le X_i,Y_i \le 10^9
入力
入力は以下の形式で標準入力から与えられる。
N K X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
出力
答えを整数として出力せよ。
入力例 1
6 5 2 0 5 2 0 3 3 2 3 4 1 5
出力例 1
3
このケースについて、横を x 軸、縦を y 軸として図示したものが以下です。

例えば、図中の矢印に従って 4 度の移動を行った後、図中に示した一辺が 3 の正方形で全ての点を内部または周上に含むことができ、これが最小値であることが示せます。
入力例 2
4 400000000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 2
0
最初から全ての点が同じ座標に存在します。
例えば操作を 0 回行う (即ち、全く行わない) ことにより、全ての点を同じ座標に存在させられるので、この入力に対する答えは 0 です。
入力例 3
10 998244353 489733278 189351894 861289363 30208889 450668761 133103889 306319121 739571083 409648209 922270934 930832199 304946211 358683490 923133355 369972904 539399938 915030547 735320146 386219602 277971612
出力例 3
484373824
Score : 525 points
Problem Statement
There are N points labeled 1, 2, \dots, N on the xy-plane. Point i is located at coordinates (X_i, Y_i).
You can perform the following operation between 0 and K times, inclusive.
- First, choose one of the N points. Let k be the selected point, and assume it is currently at (x, y).
- Next, choose and execute one of the following four actions:
- Move point k along the x-axis by +1. The coordinates of point k become (x+1, y).
- Move point k along the x-axis by -1. The coordinates of point k become (x-1, y).
- Move point k along the y-axis by +1. The coordinates of point k become (x, y+1).
- Move point k along the y-axis by -1. The coordinates of point k become (x, y-1).
- It is allowed to have multiple points at the same coordinates. Note that the input may already have multiple points at the same coordinates.
After all your operations, draw one square that includes all the N points inside or on the circumference, with each side parallel to the x- or y-axis.
Find the minimum possible value for the length of a side of this square. This value can be shown to be an integer since all points are always on lattice points.
In particular, if all points can be made to exist at the same coordinates, the answer is considered to be 0.
Constraints
- All input values are integers.
- 1 \le N \le 2 \times 10^5
- 0 \le K \le 4 \times 10^{14}
- 0 \le X_i, Y_i \le 10^9
Input
Input is given from Standard Input in the following format:
N K X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
Output
Print the answer as an integer.
Sample Input 1
6 5 2 0 5 2 0 3 3 2 3 4 1 5
Sample Output 1
3
The figure below illustrates this case with the horizontal x-axis and the vertical y-axis.

For example, after performing four moves following the arrows in the figure, you can include all points inside or on the circumference of the square shown in the figure with a side length of 3, and this can be shown to be the minimum value.
Sample Input 2
4 400000000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 2
0
All points already exist at the same coordinates from the beginning.
For example, by performing zero operations, all points can be made to exist at the same coordinates, so the answer for this input is 0.
Sample Input 3
10 998244353 489733278 189351894 861289363 30208889 450668761 133103889 306319121 739571083 409648209 922270934 930832199 304946211 358683490 923133355 369972904 539399938 915030547 735320146 386219602 277971612
Sample Output 3
484373824