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
配点 : 100 点
問題文
N 個の箱が横一列に並んでおり、そのうちのいくつかの箱にはクッキーが入っています。
各箱の状態は長さ N の文字列 S によって表されます。
具体的には、左から i\ (1\leq i\leq N) 番目の箱は、S の i 文字目が @ のときクッキーが 1 枚入っており、. のとき空き箱です。
高橋君は今からの D 日間、一日一回ずつ、これらの箱のいずれかに入ったクッキーを 1 枚選んで食べます。
N 個の箱のうち、D 日間が経過した後に空き箱であるものはいくつあるか求めてください。 (この値は高橋君が各日でどのクッキーを選ぶかによらないことが証明できます。)
なお、S には @ が D 個以上含まれることが保証されます。
制約
- 1\leq D \leq N \leq 100
- N,D は整数
- S は
@と.からなる長さ N の文字列 - S には
@が D 個以上含まれる
入力
入力は以下の形式で標準入力から与えられる。
N D S
出力
N 個の箱のうち、D 日間が経過した後に空き箱であるものの個数を出力せよ。
入力例 1
5 2 .@@.@
出力例 1
4
例えば、高橋君は以下のように行動する可能性があります。
- 1 日目:左から 2,3,5 番目の箱にクッキーが入っている。左から 2 番目の箱に入っているクッキーを選んで食べる。
- 2 日目:左から 3,5 番目の箱にクッキーが入っている。左から 5 番目の箱に入っているクッキーを選んで食べる。
- 2 日間が経過した後、左から 3 番目の箱にのみクッキーが入っている。よって、5 個の箱のうち 4 箱が空き箱である。
高橋君が各日で選ぶクッキーはこの例とは異なる可能性もありますが、いずれにせよ 2 日間が経過した後には 4 箱が空き箱です。 よって答えは 4 です。
入力例 2
3 3 @@@
出力例 2
3
入力例 3
10 4 @@@.@@.@@.
出力例 3
7
Score: 100 points
Problem Statement
There are N boxes arranged in a row, and some of these boxes contain cookies.
The state of these boxes is represented by a string S of length N.
Specifically, the i-th box (1\leq i \leq N) from the left contains one cookie if the i-th character of S is @, and is empty if it is ..
Over the next D days, Takahashi will choose and eat one cookie per day from among the cookies in these boxes.
Determine how many of the N boxes will be empty after D days have passed. (It can be proved that this value does not depend on which cookies Takahashi chooses each day.)
It is guaranteed that S contains at least D occurrences of @.
Constraints
- 1 \leq D \leq N \leq 100
- N and D are integers.
- S is a string of length N consisting of
@and.. - S contains at least D occurrences of
@.
Input
The input is given from Standard Input in the following format:
N D S
Output
Print the number of boxes that will be empty after D days have passed among the N boxes.
Sample Input 1
5 2 .@@.@
Sample Output 1
4
For example, Takahashi might act as follows:
- Day 1: There are cookies in the 2nd, 3rd, and 5th boxes from the left. He chooses the cookie in the 2nd box to eat.
- Day 2: There are cookies in the 3rd and 5th boxes. He chooses the cookie in the 5th box to eat.
- After two days have passed, only the 3rd box from the left contains a cookie. Therefore, four out of the five boxes are empty.
Even though Takahashi might choose differently on each day than in this example, there will still be four empty boxes after two days. Therefore, the answer is 4.
Sample Input 2
3 3 @@@
Sample Output 2
3
Sample Input 3
10 4 @@@.@@.@@.
Sample Output 3
7
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
座標平面上に N 枚の長方形のシートが張られています。
各シートが覆う長方形領域の各辺はそれぞれ x 軸または y 軸と平行であり、
具体的には、i 枚目のシートはちょうど A_i \leq x\leq B_i かつ C_i \leq y\leq D_i をみたす領域全体を覆っています。
1 枚以上のシートによって覆われている領域 の面積を S とすると、
S は制約の条件下で整数となる事が証明できます。
S を整数の形で出力してください。
制約
- 2\leq N\leq 100
- 0\leq A_i<B_i\leq 100
- 0\leq C_i<D_i\leq 100
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 B_1 C_1 D_1 A_2 B_2 C_2 D_2 \vdots A_N B_N C_N D_N
出力
1 枚以上のシートによって覆われている領域の面積 S を整数で出力せよ。
入力例 1
3 0 5 1 3 1 4 0 5 2 5 2 4
出力例 1
20
3 枚のシートによって覆われている領域は次のようになります。
ここで、赤色・黄色・青色はそれぞれ 1 枚目・ 2 枚目・ 3 枚目のシートによって覆われている領域を表しています。

よって、1 枚以上のシートによって覆われている領域の面積は S=20 となります。
入力例 2
2 0 100 0 100 0 100 0 100
出力例 2
10000
異なるシートが同じ領域を覆っている事があることに注意してください。
入力例 3
3 0 1 0 1 0 3 0 5 5 10 0 10
出力例 3
65
Score : 200 points
Problem Statement
There are N rectangular sheets spread out on a coordinate plane.
Each side of the rectangular region covered by each sheet is parallel to the x- or y-axis.
Specifically, the i-th sheet covers exactly the region satisfying A_i \leq x\leq B_i and C_i \leq y\leq D_i.
Let S be the area of the region covered by one or more sheets. It can be proved that S is an integer under the constraints.
Print S as an integer.
Constraints
- 2\leq N\leq 100
- 0\leq A_i<B_i\leq 100
- 0\leq C_i<D_i\leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 B_1 C_1 D_1 A_2 B_2 C_2 D_2 \vdots A_N B_N C_N D_N
Output
Print the area S of the region covered by one or more sheets as an integer.
Sample Input 1
3 0 5 1 3 1 4 0 5 2 5 2 4
Sample Output 1
20
The three sheets cover the following regions.
Here, red, yellow, and blue represent the regions covered by the first, second, and third sheets, respectively.

Therefore, the area of the region covered by one or more sheets is S=20.
Sample Input 2
2 0 100 0 100 0 100 0 100
Sample Output 2
10000
Note that different sheets may cover the same region.
Sample Input 3
3 0 1 0 1 0 3 0 5 5 10 0 10
Sample Output 3
65
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ N の数列 A=(A_1,A_2,\dots,A_N) と、長さ M の数列 B=(B_1,B_2,\dots,B_M) が与えられます。ここで、A,B のすべての要素は互いに相異なります。A,B のすべての要素を昇順に並べた長さ N+M の数列 C=(C_1,C_2,\dots,C_{N+M}) において、A に現れる要素が2つ連続するかどうか判定してください。
制約
- 1\leq N,M \leq 100
- 1\leq A_i,B_j \leq 200
- A_1, A_2, \dots, A_N, B_1, B_2, \dots, B_M は相異なる
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N B_1 B_2 \dots B_M
出力
A に現れる要素が C において2つ連続するならば Yes を、そうでないなら No を出力せよ。
入力例 1
3 2 3 2 5 4 1
出力例 1
Yes
C=(1,2,3,4,5) です。A に現れる 2,3 が C で連続しているため、Yes を出力します。
入力例 2
3 2 3 1 5 4 2
出力例 2
No
C=(1,2,3,4,5) です。A に現れる要素が C で連続している箇所はないため、No を出力します。
入力例 3
1 1 1 2
出力例 3
No
Score : 200 points
Problem Statement
You are given a sequence A=(A_1,A_2,\dots,A_N) of length N and a sequence B=(B_1,B_2,\dots,B_M) of length M. Here, all elements of A and B are pairwise distinct. Determine whether the sequence C=(C_1,C_2,\dots,C_{N+M}) formed by sorting all elements of A and B in ascending order contains two consecutive elements appearing in A.
Constraints
- 1 \leq N, M \leq 100
- 1 \leq A_i, B_j \leq 200
- A_1, A_2, \dots, A_N, B_1, B_2, \dots, B_M are distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N B_1 B_2 \dots B_M
Output
If C contains two consecutive elements appearing in A, print Yes; otherwise, print No.
Sample Input 1
3 2 3 2 5 4 1
Sample Output 1
Yes
C=(1,2,3,4,5). Since 2 and 3 from A occur consecutively in C, print Yes.
Sample Input 2
3 2 3 1 5 4 2
Sample Output 2
No
C=(1,2,3,4,5). Since no two elements from A occur consecutively in C, print No.
Sample Input 3
1 1 1 2
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 曲からなるプレイリストがあり、曲には 1, \dots, N の番号が付けられています。
曲 i の長さは A_i 秒です。
プレイリストを再生すると、曲 1、曲 2、\ldots、曲 N の順に流れます。曲 N が流れ終わると、再び曲 1 から順に流れていきます。ある曲の途中で次の曲が流れることはなく、曲が流れ終わると、その瞬間に次の曲が流れ始めます。
プレイリストを再生してから T 秒後に流れているのはどの曲ですか?また、その曲が流れ始めてから何秒の時点ですか?
ただし、T 秒後ちょうどに曲が切り替わるような入力は与えられません。
制約
- 1 \leq N \leq 10^5
- 1 \leq T \leq 10^{18}
- 1 \leq A_i \leq 10^9
- プレイリストを再生して T 秒後ちょうどに曲が切り替わることはない
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N T A_1 \ldots A_N
出力
プレイリストを再生してから T 秒後に流れている曲の番号と、その曲が流れ始めてから何秒たったかを表す整数を空白区切りで出力せよ。
入力例 1
3 600 180 240 120
出力例 1
1 60
プレイリストを再生してからの様子は次のようになります。
- 0 秒後から 180 秒後まで曲 1 が流れる。
- 180 秒後から 420 秒後まで曲 2 が流れる。
- 420 秒後から 540 秒後まで曲 3 が流れる。
- 540 秒後から 720 秒後まで曲 1 が流れる。
- 720 秒後から 960 秒後まで曲 2 が流れる。
- \qquad\vdots
600 秒後の時点で流れているのは曲 1 であり、流れ始めて 60 秒の時点です。
入力例 2
3 281 94 94 94
出力例 2
3 93
入力例 3
10 5678912340 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 3
6 678912340
Score : 300 points
Problem Statement
We have a playlist with N songs numbered 1, \dots, N.
Song i lasts A_i seconds.
When the playlist is played, song 1, song 2, \ldots, and song N play in this order. When song N ends, the playlist repeats itself, starting from song 1 again. While a song is playing, the next song does not play; when a song ends, the next song starts immediately.
At exactly T seconds after the playlist starts playing, which song is playing? Also, how many seconds have passed since the start of that song?
There is no input where the playlist changes songs at exactly T seconds after it starts playing.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq T \leq 10^{18}
- 1 \leq A_i \leq 10^9
- The playlist does not change songs at exactly T seconds after it starts playing.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N T A_1 \ldots A_N
Output
Print an integer representing the song that is playing at exactly T seconds after the playlist starts playing, and an integer representing the number of seconds that have passed since the start of that song, separated by a space.
Sample Input 1
3 600 180 240 120
Sample Output 1
1 60
When the playlist is played, the following happens. (Assume that it starts playing at time 0.)
- From time 0 to time 180, song 1 plays.
- From time 180 to time 420, song 2 plays.
- From time 420 to time 540, song 3 plays.
- From time 540 to time 720, song 1 plays.
- From time 720 to time 960, song 2 plays.
- \qquad\vdots
At time 600, song 1 is playing, and 60 seconds have passed since the start of that song.
Sample Input 2
3 281 94 94 94
Sample Output 2
3 93
Sample Input 3
10 5678912340 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 3
6 678912340
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
整数列 A = (A_1, A_2, \ldots, A_N) が与えられます。
以下の操作をちょうど K 回行った後の A の各要素の和として考えられる最小値を求めてください。
- 整数 x を選ぶ。A_i = x なる各 i について A_i の値を 0 に置き換える。
制約
- 1 \leq K \leq N \leq 3 \times 10^5
- 1 \leq A_i \leq 10^9
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
6 2 7 2 7 2 2 9
出力例 1
6
はじめ、A = (7, 2, 7, 2, 2, 9) です。
x = 9 として操作を行うと、A = (7, 2, 7, 2, 2, 0) となります。
次に x = 7 として操作を行うと、A = (0, 2, 0, 2, 2, 0) となります。
このとき、A の各要素の和は 0 + 2 + 0 + 2 + 2 + 0 = 6 となります。
入力例 2
8 6 1 2 3 4 1 2 3 4
出力例 2
0
入力例 3
10 2 3 3 4 1 1 3 3 1 5 1
出力例 3
8
Score : 300 points
Problem Statement
You are given an integer sequence A = (A_1, A_2, \ldots, A_N).
Find the minimum possible sum of all elements of A after performing the following operation exactly K times.
- Choose an integer x. For each i such that A_i = x, replace the value of A_i with 0.
Constraints
- 1 \leq K \leq N \leq 3 \times 10^5
- 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 K A_1 A_2 \ldots A_N
Output
Output the answer.
Sample Input 1
6 2 7 2 7 2 2 9
Sample Output 1
6
Initially, A = (7, 2, 7, 2, 2, 9).
Performing the operation with x = 9 gives A = (7, 2, 7, 2, 2, 0).
Next, performing the operation with x = 7 gives A = (0, 2, 0, 2, 2, 0).
At this point, the sum of all elements of A is 0 + 2 + 0 + 2 + 2 + 0 = 6.
Sample Input 2
8 6 1 2 3 4 1 2 3 4
Sample Output 2
0
Sample Input 3
10 2 3 3 4 1 1 3 3 1 5 1
Sample Output 3
8
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 425 点
問題文
H 行 W 列のグリッドがあります。上から i 行目、左から j 列目のマス目を (i, j) と表します。各マスの状態は文字 A_{i,j} で表され、意味は以下の通りです。
.: 空きマス。#: 障害物。S: 空きマスかつスタート地点。T: 空きマスかつゴール地点。
高橋君は、今いるマスから上下左右に隣り合う空きマスへ、エネルギーを 1 消費して移動することができます。ただし、エネルギーが 0 の状態で移動することはできず、またグリッドの外へ移動することはできません。
グリッドには合計で N 個の薬があります。i 番目の薬は空きマス (R_i, C_i) にあり、使うとエネルギーを E_i にすることができます。必ずしもエネルギーが増えるとは限らないことに注意してください。高橋君は自分のいるマスにある薬を使うことができます。使った薬はなくなります。
高橋君ははじめエネルギー 0 の状態でスタート地点にいて、ゴール地点まで移動したいです。これが可能かどうか判定してください。
制約
- 1 \leq H, W \leq 200
- A_{i, j} は
.,#,S,Tのいずれかである。 SとTは A_{i, j} にそれぞれちょうど 1 つ存在する。- 1 \leq N \leq 300
- 1 \leq R_i \leq H
- 1 \leq C_i \leq W
- i \neq j ならば (R_i, C_i) \neq (R_j, C_j)
- A_{R_i, C_i} は
#でない。 - 1 \leq E_i \leq HW
入力
入力は以下の形式で標準入力から与えられる。
H W
A_{1, 1}A_{1, 2}\cdotsA_{1, W}
A_{2, 1}A_{2, 2}\cdotsA_{2, W}
\vdots
A_{H, 1}A_{H, 2}\cdotsA_{H, W}
N
R_1 C_1 E_1
R_2 C_2 E_2
\vdots
R_N C_N E_N
出力
高橋君がスタート地点からゴール地点へ移動することが可能なら Yes 、不可能なら No を出力せよ。
入力例 1
4 4 S... #..# #... ..#T 4 1 1 3 1 3 5 3 2 1 2 3 1
出力例 1
Yes
例えば、以下のようにしてゴール地点へ移動することができます。
- 薬 1 を使う。エネルギーが 3 になる。
- (1, 2) へ移動する。エネルギーが 2 になる。
- (1, 3) へ移動する。エネルギーが 1 になる。
- 薬 2 を使う。エネルギーが 5 になる。
- (2, 3) へ移動する。エネルギーが 4 になる。
- (3, 3) へ移動する。エネルギーが 3 になる。
- (3, 4) へ移動する。エネルギーが 2 になる。
- (4, 4) へ移動する。エネルギーが 1 になる。
この移動の途中には (2, 3) にも薬がありますが、これを使うとゴールできません。
入力例 2
2 2 S. T. 1 1 2 4
出力例 2
No
高橋君はスタート地点から移動することができません。
入力例 3
4 5 ..#.. .S##. .##T. ..... 3 3 1 5 1 2 3 2 2 1
出力例 3
Yes
Score: 425 points
Problem Statement
There is a grid with H rows and W columns. Let (i, j) denote the cell at the i-th row from the top and the j-th column from the left. The state of each cell is represented by the character A_{i,j}, which means the following:
.: An empty cell.#: An obstacle.S: An empty cell and the start point.T: An empty cell and the goal point.
Takahashi can move from his current cell to a vertically or horizontally adjacent empty cell by consuming 1 energy. He cannot move if his energy is 0, nor can he exit the grid.
There are N medicines in the grid. The i-th medicine is at the empty cell (R_i, C_i) and can be used to set the energy to E_i. Note that the energy does not necessarily increase. He can use the medicine in his current cell. The used medicine will disappear.
Takahashi starts at the start point with 0 energy and wants to reach the goal point. Determine if this is possible.
Constraints
- 1 \leq H, W \leq 200
- A_{i, j} is one of
.,#,S, andT. - Each of
SandTexists exactly once in A_{i, j}. - 1 \leq N \leq 300
- 1 \leq R_i \leq H
- 1 \leq C_i \leq W
- (R_i, C_i) \neq (R_j, C_j) if i \neq j.
- A_{R_i, C_i} is not
#. - 1 \leq E_i \leq HW
Input
The input is given from Standard Input in the following format:
H W
A_{1, 1}A_{1, 2}\cdotsA_{1, W}
A_{2, 1}A_{2, 2}\cdotsA_{2, W}
\vdots
A_{H, 1}A_{H, 2}\cdotsA_{H, W}
N
R_1 C_1 E_1
R_2 C_2 E_2
\vdots
R_N C_N E_N
Output
If Takahashi can reach the goal point from the start point, print Yes; otherwise, print No.
Sample Input 1
4 4 S... #..# #... ..#T 4 1 1 3 1 3 5 3 2 1 2 3 1
Sample Output 1
Yes
For example, he can reach the goal point as follows:
- Use medicine 1. Energy becomes 3.
- Move to (1, 2). Energy becomes 2.
- Move to (1, 3). Energy becomes 1.
- Use medicine 2. Energy becomes 5.
- Move to (2, 3). Energy becomes 4.
- Move to (3, 3). Energy becomes 3.
- Move to (3, 4). Energy becomes 2.
- Move to (4, 4). Energy becomes 1.
There is also medicine at (2, 3) along the way, but using it will prevent him from reaching the goal.
Sample Input 2
2 2 S. T. 1 1 2 4
Sample Output 2
No
Takahashi cannot move from the start point.
Sample Input 3
4 5 ..#.. .S##. .##T. ..... 3 3 1 5 1 2 3 2 2 1
Sample Output 3
Yes
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: 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