実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
英大文字からなる長さ 3 の文字列 S が与えられます。S が ACE、BDF、CEG、DFA、EGB、FAC、GBD のいずれかと等しいとき Yes を、そうでないとき No を出力してください。
制約
- S は英大文字からなる長さ 3 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S が ACE、BDF、CEG、DFA、EGB、FAC、GBD のいずれかと等しいとき Yes を、そうでないとき No を出力せよ。
入力例 1
ABC
出力例 1
No
S = ABC のとき、S は ACE、BDF、CEG、DFA、EGB、FAC、GBD のいずれとも等しくないので No を出力します。
入力例 2
FAC
出力例 2
Yes
入力例 3
XYX
出力例 3
No
Score : 100 points
Problem Statement
Given a length-3 string S consisting of uppercase English letters, print Yes if S equals one of ACE, BDF, CEG, DFA, EGB, FAC, and GBD; print No otherwise.
Constraints
- S is a length-3 string consisting of uppercase English letters.
Input
The input is given from Standard Input in the following format:
S
Output
Print Yes if S equals one of ACE, BDF, CEG, DFA, EGB, FAC, and GBD; print No otherwise.
Sample Input 1
ABC
Sample Output 1
No
When S = ABC, S does not equal any of ACE, BDF, CEG, DFA, EGB, FAC, and GBD, so No should be printed.
Sample Input 2
FAC
Sample Output 2
Yes
Sample Input 3
XYX
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
0 と 1 の 2 種類の文字からなる文字列 s が与えられます。
s に含まれる 0 を 1 に、1 を 0 に置き換えた文字列を出力してください。
制約
- s の長さは 1 以上 10 以下
- s は
0と1の 2 種類の文字からなる
入力
入力は以下の形式で標準入力から与えられる。
s
出力
答えを 1 行で出力せよ。
入力例 1
01
出力例 1
10
s の 1 文字目は 1 なので、1 文字目に出力すべき文字は 0 です。
s の 2 文字目は 0 なので、2 文字目に出力すべき文字は 1 です。
入力例 2
1011
出力例 2
0100
入力例 3
100100001
出力例 3
011011110
Score : 100 points
Problem Statement
You are given a string s consisting of two kinds of characters, 0 and 1.
Print the string obtained by replacing 0 with 1 and 1 with 0 in s.
Constraints
- The length of s is between 1 and 10, inclusive.
- s consists of two kinds of characters,
0and1.
Input
The input is given from Standard Input in the following format:
s
Output
Print the answer in a single line.
Sample Input 1
01
Sample Output 1
10
The 1-st character of s is 1, so the 1-st character to print is 0.
The 2-nd character of s is 0, so the 2-nd character to print is 1.
Sample Input 2
1011
Sample Output 2
0100
Sample Input 3
100100001
Sample Output 3
011011110
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字からなる 3 つの文字列 S_1, S_2, S_3 と、1、2、3 のみからなる文字列 T が与えられます。
T の各文字に対応する文字列を連結してできる文字列を出力してください。より厳密には、以下の指示にしたがって文字列を出力してください。
- 1 \leq i \leq |T| を満たす整数 i に対し、文字列 s_i を次のように定める。
- T の i 文字目が
1のとき、S_1 - T の i 文字目が
2のとき、S_2 - T の i 文字目が
3のとき、S_3
- T の i 文字目が
- s_1, s_2, \dots, s_{|T|} をこの順に連結してできる文字列を出力する。
制約
- 1 \leq |S_1|, |S_2|, |S_3| \leq 10
- 1 \leq |T| \leq 1000
- S_1, S_2, S_3 は英小文字からなる。
- T は
1、2、3のみからなる。
入力
入力は以下の形式で標準入力から与えられる。
S_1 S_2 S_3 T
出力
答えを出力せよ。
入力例 1
mari to zzo 1321
出力例 1
marizzotomari
s_1 = mari, s_2 = zzo, s_3 = to, s_4 = mari であるので、これらを連結してできる文字列である marizzotomari を出力します。
入力例 2
abra cad abra 123
出力例 2
abracadabra
入力例 3
a b c 1
出力例 3
a
Score : 200 points
Problem Statement
You are given three strings S_1, S_2, S_3 consisting of lowercase English letters, and a string T consisting of 1, 2, 3.
Concatenate the three strings according to the characters in T and print the resulting string. Formally, conform to the following instructions.
- For each integer i such that 1 \leq i \leq |T|, let the string s_i be defined as follows:
- S_1, if the i-th character of T is
1; - S_2, if the i-th character of T is
2; - S_3, if the i-th character of T is
3.
- S_1, if the i-th character of T is
- Concatenate the strings s_1, s_2, \dots, s_{|T|} in this order and print the resulting string.
Constraints
- 1 \leq |S_1|, |S_2|, |S_3| \leq 10
- 1 \leq |T| \leq 1000
- S_1, S_2, and S_3 consist of lowercase English letters.
- T consists of
1,2, and3.
Input
Input is given from Standard Input in the following format:
S_1 S_2 S_3 T
Output
Print the answer.
Sample Input 1
mari to zzo 1321
Sample Output 1
marizzotomari
We have s_1 = mari, s_2 = zzo, s_3 = to, s_4 = mari. Concatenate these and print the resulting string: marizzotomari.
Sample Input 2
abra cad abra 123
Sample Output 2
abracadabra
Sample Input 3
a b c 1
Sample Output 3
a
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
xy 平面上に N 人の人 1,2,\dots,N がおり、人 i は座標 (X_i,Y_i) にいます。
このうち、 K 人の人 A_1,A_2,\dots,A_K に同じ強さの明かりを持たせます。
座標 (x,y) にいる人が強さ R の明かりを持っている時、その明かりによって中心 (x,y) 、半径 R の円の内部全体(境界を含む)が照らされます。
すべての人が少なくとも 1 つの明かりによって照らされるために必要な明かりの強さの最小値を求めてください。
制約
- 入力は全て整数
- 1 \le K < N \le 1000
- 1 \le A_1 < A_2 < \dots < A_K \le N
- |X_i|,|Y_i| \le 10^5
- i \neq j ならば (X_i,Y_i) \neq (X_j,Y_j)
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_K X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
出力
答えを実数として出力せよ。
出力された解と想定解との絶対誤差または相対誤差が 10^{-5} 以下であるならば、出力は正しいと見なされる。
入力例 1
4 2 2 3 0 0 0 1 1 2 2 0
出力例 1
2.23606797749978969
この入力では人が 4 人おり、そのうち人 2,3 が明かりを持ちます。
R \ge \sqrt{5} \approx 2.236068 である時、すべての人が少なくとも 1 つの明かりによって照らされます。
入力例 2
2 1 2 -100000 -100000 100000 100000
出力例 2
282842.712474619009
入力例 3
8 3 2 6 8 -17683 17993 93038 47074 58079 -57520 -41515 -89802 -72739 68805 24324 -73073 71049 72103 47863 19268
出力例 3
130379.280458974768
Score : 200 points
Problem Statement
There are N people numbered 1, 2, \dots, N in the xy-plane. Person i is at the coordinates (X_i, Y_i).
K of these people, Persons A_1, A_2, \dots, A_K, will receive lights of the same strength.
When a person at coordinates (x, y) has a light of strength R, it lights up the interior of a circle of radius R centered at (x, y) (including the boundary).
Find the minimum strength of the lights needed for every person to be lit by at least one light.
Constraints
- All values in input are integers.
- 1 \le K < N \le 1000
- 1 \le A_1 < A_2 < \dots < A_K \le N
- |X_i|,|Y_i| \le 10^5
- (X_i,Y_i) \neq (X_j,Y_j), if i \neq j.
Input
Input is given from Standard Input in the following format:
N K A_1 A_2 \dots A_K X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
Output
Print the answer as a real number.
Your output will be considered correct if its absolute or relative error from the judge's output is at most 10^{-5}.
Sample Input 1
4 2 2 3 0 0 0 1 1 2 2 0
Sample Output 1
2.23606797749978969
This input contains four people. Among them, Persons 2 and 3 will have lights.
Every person will be lit by at least one light if R \ge \sqrt{5} \approx 2.236068.
Sample Input 2
2 1 2 -100000 -100000 100000 100000
Sample Output 2
282842.712474619009
Sample Input 3
8 3 2 6 8 -17683 17993 93038 47074 58079 -57520 -41515 -89802 -72739 68805 24324 -73073 71049 72103 47863 19268
Sample Output 3
130379.280458974768
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
英小文字からなる文字列 S が与えられます。
S の先頭に a をいくつか( 0 個でも良い)つけ加えて回文にすることができるか判定してください。
ただし、長さ N の文字列 A=A_1A_2\ldots A_N が回文であるとは、すべての 1\leq i\leq N について A_i=A_{N+1-i} が成り立っていることをいいます。
制約
- 1 \leq \lvert S \rvert \leq 10^6
- S は英小文字のみからなる。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
S の先頭に a をいくつかつけ加えて回文にすることができるならば Yes を、そうでないならば No を出力せよ。
入力例 1
kasaka
出力例 1
Yes
kasaka の先頭に a を 1 つ付け加えることによって、akasaka となり回文となるため Yes を出力します。
入力例 2
atcoder
出力例 2
No
atcoder の先頭に a をいくつ付け加えても回文となる事はありません。
入力例 3
php
出力例 3
Yes
php はそれ自体回文です。S の先頭に付け加える a は 0 個でも許されるため、Yes を出力します。
Score : 300 points
Problem Statement
Given is a string S consisting of lowercase English letters.
Determine whether adding some number of a's (possibly zero) at the beginning of S can make it a palindrome.
Here, a string of length N, A=A_1A_2\ldots A_N, is said to be a palindrome when A_i=A_{N+1-i} for every 1\leq i\leq N.
Constraints
- 1 \leq \lvert S \rvert \leq 10^6
- S consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
If adding some number of a's (possibly zero) at the beginning of S can make it a palindrome, print Yes; otherwise, print No.
Sample Input 1
kasaka
Sample Output 1
Yes
By adding one a at the beginning of kasaka, we have akasaka, which is a palindrome, so Yes should be printed.
Sample Input 2
atcoder
Sample Output 2
No
Adding any number of a's at the beginning of atcoder does not make it a palindrome.
Sample Input 3
php
Sample Output 3
Yes
php itself is a palindrome. Adding zero a's at the beginning of S is allowed, so Yes should be printed.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
xy 平面上に 1 から N までの番号が付いた N 個の点があります。
点 i は座標 (X_i,Y_i) にあり、相異なる 2 点は異なる位置に存在します。
この N 点から 3 点を選ぶとき、選ばれた 3 点を線分で結んだ図形が正の面積を持つ三角形になるような点の選び方の総数を求めてください。
制約
- 入力は全て整数である
- 3 \le N \le 300
- -10^9 \le X_i,Y_i \le 10^9
- i \neq j ならば (X_i,Y_i) \neq (X_j,Y_j)
入力
入力は以下の形式で標準入力から与えられる。
N X_1 Y_1 X_2 Y_2 \dots X_N Y_N
出力
答えを整数として出力せよ。
入力例 1
4 0 1 1 3 1 1 -1 -1
出力例 1
3
点を図示すると、以下のようになります。

三角形をなすような点の選び方は、 \{1,2,3\},\{1,3,4\},\{2,3,4\} の 3 つです。
入力例 2
20 224 433 987654321 987654321 2 0 6 4 314159265 358979323 0 0 -123456789 123456789 -1000000000 1000000000 124 233 9 -6 -4 0 9 5 -7 3 333333333 -333333333 -9 -1 7 -10 -1 5 324 633 1000000000 -1000000000 20 0
出力例 2
1124
Score : 300 points
Problem Statement
In the xy-plane, we have N points numbered 1 through N.
Point i is at the coordinates (X_i,Y_i). Any two different points are at different positions.
Find the number of ways to choose three of these N points so that connecting the chosen points with segments results in a triangle with a positive area.
Constraints
- All values in input are integers.
- 3 \le N \le 300
- -10^9 \le X_i,Y_i \le 10^9
- (X_i,Y_i) \neq (X_j,Y_j) if i \neq j.
Input
Input is given from Standard Input in the following format:
N X_1 Y_1 X_2 Y_2 \dots X_N Y_N
Output
Print the answer as an integer.
Sample Input 1
4 0 1 1 3 1 1 -1 -1
Sample Output 1
3
The figure below illustrates the points.

There are three ways to choose points that form a triangle: \{1,2,3\},\{1,3,4\},\{2,3,4\}.
Sample Input 2
20 224 433 987654321 987654321 2 0 6 4 314159265 358979323 0 0 -123456789 123456789 -1000000000 1000000000 124 233 9 -6 -4 0 9 5 -7 3 333333333 -333333333 -9 -1 7 -10 -1 5 324 633 1000000000 -1000000000 20 0
Sample Output 2
1124
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
高橋君はあるサービスで使うユーザー名を決めるのに困っています。彼を助けるプログラムを書いてください。
以下の条件をすべて満たす文字列 X を 1 つ求めてください。
- X は次の手順で得られる文字列である。
- N 個の文字列 S_1,S_2,\ldots,S_N を好きな順番で並べたものを S_1', S_2', \ldots,S_N' とする。そして、S_1'、( 1 個以上の
_)、S_2'、( 1 個以上の_)、\ldots、( 1 個以上の_)、S_N' をこの順番で連結したものを X とする。
- N 個の文字列 S_1,S_2,\ldots,S_N を好きな順番で並べたものを S_1', S_2', \ldots,S_N' とする。そして、S_1'、( 1 個以上の
- X の文字数は 3 以上 16 以下である。
- X は M 個の文字列 T_1,T_2,\ldots,T_M のいずれとも一致しない。
ただし、条件をすべて満たす文字列 X が存在しない場合は代わりに -1 と出力してください。
制約
- 1 \leq N \leq 8
- 0 \leq M \leq 10^5
- N,M は整数
- 1 \leq |S_i| \leq 16
- N-1+\sum{|S_i|} \leq 16
- i \neq j ならば S_i \neq S_j
- S_i は英小文字のみからなる文字列
- 3 \leq |T_i| \leq 16
- i \neq j ならば T_i \neq T_j
- T_i は英小文字と
_のみからなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N T_1 T_2 \vdots T_M
出力
条件をすべて満たす文字列 X を 1 つ出力せよ。ただし、条件をすべて満たす文字列 X が存在しない場合は代わりに -1 を出力せよ。
答えが複数存在する場合、どれを出力しても良い。
入力例 1
1 1 chokudai chokudai
出力例 1
-1
条件のうち 1 番目と 2 番目を満たす文字列は X= chokudai しかありませんが、これは T_1 と一致します。
このため、条件をすべて満たす文字列 X が存在せず、-1 が正しい出力となります。
入力例 2
2 2 choku dai chokudai choku_dai
出力例 2
dai_choku
この他に、choku__dai (choku と dai の間の _ が 2 つ) 等も条件をすべて満たします。
入力例 3
2 2 chokudai atcoder chokudai_atcoder atcoder_chokudai
出力例 3
-1
chokudai__atcoder や atcoder__chokudai (chokudai と atcoder の間の _ が 2 つ)は文字数が 17 なので 2 番目の条件を満たしません。
入力例 4
4 4 ab cd ef gh hoge fuga ____ _ab_cd_ef_gh_
出力例 4
ab__ef___cd_gh
1 番目の条件で記述されている操作で得られないような文字列が T_i として与えられる場合があります。
Score : 400 points
Problem Statement
Takahashi is having trouble with deciding a username for a service. Write a code to help him.
Find a string X that satisfies all of the following conditions:
- X is obtained by the following procedure:
- Let S_1', S_2', \ldots,S_N' be a permutation of S_1, S_2, \ldots,S_N. Let X be the concatenation of S_1', (1 or more copies of
_), S_2', (1 or more copies of_), \ldots, (1 or more copies of_), and S_N', in this order.
- Let S_1', S_2', \ldots,S_N' be a permutation of S_1, S_2, \ldots,S_N. Let X be the concatenation of S_1', (1 or more copies of
- The length of X is between 3 and 16, inclusive.
- X does not coincide with any of M strings T_1,T_2,\ldots,T_M.
If there is no X that satisfies all of the conditions, print -1 instead.
Constraints
- 1 \leq N \leq 8
- 0 \leq M \leq 10^5
- N and M are integers.
- 1 \leq |S_i| \leq 16
- N-1+\sum{|S_i|} \leq 16
- S_i \neq S_j if i \neq j.
- S_i is a string consisting of lowercase English letters.
- 3 \leq |T_i| \leq 16
- T_i \neq T_j if i \neq j.
- T_i is a string consisting of lowercase English letters and
_.
Input
Input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N T_1 T_2 \vdots T_M
Output
Print a string X that satisfies all of the conditions. If there is no X that satisfies all of the conditions, print -1 instead.
If there are multiple solutions, print any of them.
Sample Input 1
1 1 chokudai chokudai
Sample Output 1
-1
The only string that satisfies the first and second conditions is X= chokudai, but it coincides with T_1.
Thus, there is no X that satisfies all of the conditions, so -1 should be printed.
Sample Input 2
2 2 choku dai chokudai choku_dai
Sample Output 2
dai_choku
Strings like choku__dai (which has two _'s between choku and dai) also satisfy all of the conditions.
Sample Input 3
2 2 chokudai atcoder chokudai_atcoder atcoder_chokudai
Sample Output 3
-1
chokudai__atcoder and atcoder__chokudai (which have two _'s between chokudai and atcoder) have a length of 17, which violates the second condition.
Sample Input 4
4 4 ab cd ef gh hoge fuga ____ _ab_cd_ef_gh_
Sample Output 4
ab__ef___cd_gh
The given T_i may contain a string that cannot be obtained by the procedure described in the first condition.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
AtCoder国には N 個の都市があり、都市 1 , 都市 2 , \ldots , 都市 N と番号付けられています。 最初、どの 2 つの相異なる都市の間も双方向に通れる道で結ばれていましたが、老朽化が進み、これらのうち M 本の道が使えなくなってしまいました。具体的には 1\leq i \leq M について都市 U_i と都市 V_i を結ぶ道が使えなくなってしまいました。
いま、高橋君は都市 1 で始まり、都市 1 で終わる K 日間の旅をしようと考えました。都市 1 で始まり、都市 1 で終わる K 日間の旅とは、 K+1 個の都市の列 (A_0, A_1, \ldots, A_K) であって、A_0=A_K=1 をみたし、 0\leq i\leq K-1 について A_i と A_{i+1} が相異なり、かつ都市 A_i と都市 A_{i+1} が現在も使用可能な道で結ばれているものを指します。
都市 1 で始まり、都市 1 で終わる K 日間の相異なる旅の数を 998244353 で割った余りを出力してください。ただし、 2 つの K 日間の旅 (A_0, A_1, \ldots, A_K) と (B_0, B_1, \ldots, B_K) が相異なるとは、ある i が存在して A_i\neq B_i となることを言います。
制約
- 2 \leq N \leq 5000
- 0 \leq M \leq \min\left( \frac{N(N-1)}{2},5000 \right)
- 2 \leq K \leq 5000
- 1 \leq U_i<V_i \leq N
- (U_i, V_i) は全て互いに相異なる。
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N M K U_1 V_1 : U_M V_M
出力
答えを出力せよ。
入力例 1
3 1 4 2 3
出力例 1
4
次のような 4 種類の旅が存在します。
- (1,2,1,2,1)
- (1,2,1,3,1)
- (1,3,1,2,1)
- (1,3,1,3,1)
これ以外に条件をみたすようなものは無いため、 4 を出力します。
入力例 2
3 3 3 1 2 1 3 2 3
出力例 2
0
使える道が 1 本も残っておらず、条件をみたすような旅は存在しません。
入力例 3
5 3 100 1 2 4 5 2 3
出力例 3
428417047
Score : 500 points
Problem Statement
The Republic of AtCoder has N cities, called City 1, City 2, \ldots, City N. Initially, there was a bidirectional road between every pair of different cities, but M of these roads have become unusable due to deterioration over time. More specifically, for each 1\leq i \leq M, the road connecting City U_i and City V_i has become unusable.
Takahashi will go for a K-day trip that starts and ends in City 1. Formally speaking, a K-day trip that starts and ends in City 1 is a sequence of K+1 cities (A_0, A_1, \ldots, A_K) such that A_0=A_K=1 holds and for each 0\leq i\leq K-1, A_i and A_{i+1} are different and there is still a usable road connecting City A_i and City A_{i+1}.
Print the number of different K-day trips that start and end in City 1, modulo 998244353. Here, two K-day trips (A_0, A_1, \ldots, A_K) and (B_0, B_1, \ldots, B_K) are said to be different when there exists an i such that A_i\neq B_i.
Constraints
- 2 \leq N \leq 5000
- 0 \leq M \leq \min\left( \frac{N(N-1)}{2},5000 \right)
- 2 \leq K \leq 5000
- 1 \leq U_i<V_i \leq N
- All pairs (U_i, V_i) are pairwise distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M K U_1 V_1 : U_M V_M
Output
Print the answer.
Sample Input 1
3 1 4 2 3
Sample Output 1
4
There are four different trips as follows.
- (1,2,1,2,1)
- (1,2,1,3,1)
- (1,3,1,2,1)
- (1,3,1,3,1)
No other trip is valid, so we should print 4.
Sample Input 2
3 3 3 1 2 1 3 2 3
Sample Output 2
0
No road remains usable, so there is no valid trip.
Sample Input 3
5 3 100 1 2 4 5 2 3
Sample Output 3
428417047
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 550 点
問題文
数直線上にりんごの木が並んでおり、 N 個のりんごが木から落ちてきます。
具体的には 1\leq i\leq N について、時刻 T_i に座標 X_i にりんごが落ちてきます。
高橋君は耐久性が D , 長さ W のカゴを持っており、一度だけ 次の行動を取ることができます。
正整数 S, L を選ぶ。高橋君は時刻 S-0.5 に L-0.5\leq x\leq L+W-0.5 の範囲を覆うようにカゴを設置し、時刻 S+D-0.5 に回収する。 高橋君はカゴを設置してから回収するまでの間に、カゴが設置されていた範囲に落ちてきたりんごをすべて得ることができる。
高橋君は一度設置したカゴを動かしたり、回収したカゴを再度設置することはできません。
高橋君が得られるりんごの数の最大値を求めてください。
制約
- 1 \leq N\leq 2\times 10^5
- 1 \leq D\leq 2\times 10^5
- 1 \leq W\leq 2\times 10^5
- 1 \leq T_i\leq 2\times 10^5
- 1 \leq X_i\leq 2\times 10^5
- (T_i,X_i) はすべて異なる。
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N D W T_1 X_1 T_2 X_2 \vdots T_N X_N
出力
高橋君が得られるりんごの数の最大値を出力せよ。
入力例 1
8 4 3 1 1 3 4 6 4 5 2 4 2 4 3 5 5 7 3
出力例 1
5
高橋君は S=3, L=2 を選ぶと、時刻 2.5 から 6.5 までカゴを 1.5\leq x\leq 4.5 の範囲に設置します。このとき、
- 時刻 T_2=3 に 座標 X_2=4 に落ちてくるりんご
- 時刻 T_3=6 に 座標 X_3=4 に落ちてくるりんご
- 時刻 T_4=5 に 座標 X_4=2 に落ちてくるりんご
- 時刻 T_5=4 に 座標 X_5=2 に落ちてくるりんご
- 時刻 T_6=4 に 座標 X_6=3 に落ちてくるりんご
の 5 個のりんごを得ることができます。
どのように行動しても 6 個以上のりんごを得ることはできないため、5 を出力します。
Score : 550 points
Problem Statement
There are apple trees lined up on a number line, and N apples fall from the trees.
Specifically, for each 1\leq i\leq N, an apple falls at coordinate X_i at time T_i.
Takahashi has a basket with durability D and length W, and he can take the following action exactly once.
Choose positive integers S and L. He sets up the basket to cover the range L-0.5\leq x\leq L+W-0.5 at time S-0.5, and retrieves it at time S+D-0.5. He gets all the apples that fell into the range covered by the basket between the time it was set up and the time it was retrieved.
He cannot move the basket once it has been set up, nor can he set it up again once it has been retrieved.
Find the maximum number of apples that he can get.
Constraints
- 1 \leq N\leq 2\times 10^5
- 1 \leq D\leq 2\times 10^5
- 1 \leq W\leq 2\times 10^5
- 1 \leq T_i\leq 2\times 10^5
- 1 \leq X_i\leq 2\times 10^5
- All pairs (T_i,X_i) are different.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N D W T_1 X_1 T_2 X_2 \vdots T_N X_N
Output
Print the maximum number of apples that Takahashi can get.
Sample Input 1
8 4 3 1 1 3 4 6 4 5 2 4 2 4 3 5 5 7 3
Sample Output 1
5
If Takahashi chooses S=3 and L=2, he will set up the basket to cover the range 1.5\leq x\leq 4.5 from time 2.5 to 6.5. Then, he gets the following five apples:
- The apple that falls at coordinate X_2=4 at time T_2=3
- The apple that falls at coordinate X_3=4 at time T_3=6
- The apple that falls at coordinate X_4=2 at time T_4=5
- The apple that falls at coordinate X_5=2 at time T_5=4
- The apple that falls at coordinate X_6=3 at time T_6=4
There is no way to get six or more apples, so print 5.