実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
高橋君は、 N 個の地点が一直線上に並んだ道を散歩しています。地点は左から順に 1, 2, \ldots, N と番号が付けられており、番号が 1 異なる地点同士が隣接しています。
この道沿いには M 本の桜の木が植えられています。 i 番目の桜の木は地点 P_i に植えられており、高橋君がその地点を訪れると V_i 枚の花びらが落ちてきて、高橋君はそのすべてを受け取ります。各地点には桜の木は高々 1 本しか植えられていません。
高橋君は地点 S からスタートし、地点 T まで移動します。高橋君は S から T に向かって隣接する地点へ 1 地点ずつ進み、途中で引き返すことはありません。したがって、高橋君が訪れる地点は、スタート地点とゴール地点を含めて、以下のとおりです。
- S \leq T のとき: S, S+1, \ldots, T
- S > T のとき: S, S-1, \ldots, T
S = T の場合、高橋君は移動せず地点 S のみを訪れます。
高橋君は一方向にのみ進むため、各地点を訪れるのはちょうど 1 回です。高橋君が地点 S から地点 T まで移動する間に受け取る花びらの総枚数を求めてください。
制約
- 1 \leq N \leq 10^9
- 1 \leq M \leq 2 \times 10^5
- 1 \leq S \leq N
- 1 \leq T \leq N
- 1 \leq P_i \leq N (1 \leq i \leq M)
- 1 \leq V_i \leq 10^9 (1 \leq i \leq M)
- P_i \neq P_j (i \neq j)
- 入力はすべて整数である
入力
N M S T P_1 V_1 P_2 V_2 \vdots P_M V_M
- 1 行目には、地点の数を表す N と、桜の木の本数を表す M が、スペース区切りで与えられる。
- 2 行目には、スタート地点を表す S と、ゴール地点を表す T が、スペース区切りで与えられる。
- 3 行目から M + 2 行目では、各桜の木の情報が与えられる。
- 2 + i 行目には、 i 番目の桜の木が植えられている地点 P_i と、その木から落ちる花びらの枚数 V_i が、スペース区切りで与えられる。
出力
高橋君が地点 S から地点 T まで移動する間に受け取る花びらの総枚数を 1 行で出力せよ。
入力例 1
10 5 3 8 1 10 3 5 5 7 8 2 10 100
出力例 1
14
入力例 2
100 12 40 15 5 12 10 7 15 100 18 30 20 8 25 50 30 3 35 20 40 200 41 9 60 15 90 1
出力例 2
411
入力例 3
1000000000 25 999999920 999999970 1 111 2 222 100000000 333 123456789 444 400000000 555 500000000 666 700000000 777 800000100 888 999999999 999 999999910 4 999999919 70 999999920 100 999999923 1 999999930 500000000 999999934 20 999999940 300 999999945 999999999 999999950 42 999999955 17 999999960 250000000 999999966 6 999999970 8 999999971 90 999999972 3 999999980 5
出力例 3
1750000493
Score : 200 pts
Problem Statement
Takahashi is taking a walk along a road with N points arranged in a straight line. The points are numbered 1, 2, \ldots, N from left to right, and points whose numbers differ by 1 are adjacent to each other.
Along this road, M cherry blossom trees are planted. The i-th cherry blossom tree is planted at point P_i, and when Takahashi visits that point, V_i petals fall down, all of which Takahashi receives. At most one cherry blossom tree is planted at each point.
Takahashi starts at point S and moves to point T. He proceeds one adjacent point at a time from S toward T, without ever turning back. Therefore, the points Takahashi visits, including the start and goal points, are as follows:
- When S \leq T: S, S+1, \ldots, T
- When S > T: S, S-1, \ldots, T
If S = T, Takahashi does not move and only visits point S.
Since Takahashi moves in only one direction, he visits each point exactly once. Find the total number of petals Takahashi receives while moving from point S to point T.
Constraints
- 1 \leq N \leq 10^9
- 1 \leq M \leq 2 \times 10^5
- 1 \leq S \leq N
- 1 \leq T \leq N
- 1 \leq P_i \leq N (1 \leq i \leq M)
- 1 \leq V_i \leq 10^9 (1 \leq i \leq M)
- P_i \neq P_j (i \neq j)
- All input values are integers
Input
N M S T P_1 V_1 P_2 V_2 \vdots P_M V_M
- The first line contains N, the number of points, and M, the number of cherry blossom trees, separated by a space.
- The second line contains S, the start point, and T, the goal point, separated by a space.
- From the 3rd line to the (M + 2)-th line, information about each cherry blossom tree is given.
- The (2 + i)-th line contains P_i, the point where the i-th cherry blossom tree is planted, and V_i, the number of petals that fall from that tree, separated by a space.
Output
Print in one line the total number of petals Takahashi receives while moving from point S to point T.
Sample Input 1
10 5 3 8 1 10 3 5 5 7 8 2 10 100
Sample Output 1
14
Sample Input 2
100 12 40 15 5 12 10 7 15 100 18 30 20 8 25 50 30 3 35 20 40 200 41 9 60 15 90 1
Sample Output 2
411
Sample Input 3
1000000000 25 999999920 999999970 1 111 2 222 100000000 333 123456789 444 400000000 555 500000000 666 700000000 777 800000100 888 999999999 999 999999910 4 999999919 70 999999920 100 999999923 1 999999930 500000000 999999934 20 999999940 300 999999945 999999999 999999950 42 999999955 17 999999960 250000000 999999966 6 999999970 8 999999971 90 999999972 3 999999980 5
Sample Output 3
1750000493
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 266 点
問題文
高橋君は文化祭でモザイクアートを作ることになりました。
まず、高橋君は H 行 W 列のグリッド状のデザイン原案を用意しました。グリッドの各マスは #(塗りつぶし)または .(空白)のいずれかです。
高橋君はこのデザイン原案をもとに、以下の手順でモザイクアートを作成します。
手順 1:拡大
デザイン原案を縦横それぞれ K 倍に拡大します。すなわち、原案の各マスを K 行 K 列の同じ文字のブロックに置き換えることで、# と . からなる (H \times K) 行 (W \times K) 列のグリッドを得ます。
手順 2:文字の割り当て
手順 1 で得られた (H \times K) 行 (W \times K) 列のグリッドにおいて、# をすべて文字 c_1 に、. をすべて文字 c_2 にそれぞれ置き換えます。ここで c_1 と c_2 はそれぞれ英小文字 (a–z) または英大文字 (A–Z) のいずれか 1 文字です。c_1 と c_2 が同じ文字である場合もあります。
最終的に得られる (H \times K) 行 (W \times K) 列のモザイクアートを出力してください。
制約
- 1 \leq H \leq 100
- 1 \leq W \leq 100
- 1 \leq K \leq 50
- H, W, K はいずれも整数
- c_1 は英小文字 (
a–z) または英大文字 (A–Z) のいずれか 1 文字 - c_2 は英小文字 (
a–z) または英大文字 (A–Z) のいずれか 1 文字 - c_1 と c_2 は同じ文字であることもある
- S_i は
#と.からなる長さ W の文字列
入力
H W K c_1 c_2 S_1 S_2 \vdots S_H
- 1 行目には、デザイン原案の行数 H、列数 W、拡大倍率 K が空白区切りで与えられる。
- 2 行目には、
#の代わりに使う文字 c_1 と.の代わりに使う文字 c_2 が空白区切りで与えられる。 - 続く H 行にわたって、デザイン原案が与えられる。そのうち i 番目 (1 \leq i \leq H) の行には、デザイン原案の上から i 行目に対応する文字列 S_i が与えられる。S_i は
#と.からなる長さ W の文字列である。
出力
最終的に得られるモザイクアートを (H \times K) 行にわたって出力せよ。各行は長さ (W \times K) の文字列である。
入力例 1
3 3 2 X o #.# .#. #.#
出力例 1
XXooXX XXooXX ooXXoo ooXXoo XXooXX XXooXX
入力例 2
2 4 3 A B #..# .##.
出力例 2
AAABBBBBBAAA AAABBBBBBAAA AAABBBBBBAAA BBBAAAAAABBB BBBAAAAAABBB BBBAAAAAABBB
入力例 3
5 6 4 R w #....# .#..#. ..##.. .#..#. #....#
出力例 3
RRRRwwwwwwwwwwwwwwwwRRRR RRRRwwwwwwwwwwwwwwwwRRRR RRRRwwwwwwwwwwwwwwwwRRRR RRRRwwwwwwwwwwwwwwwwRRRR wwwwRRRRwwwwwwwwRRRRwwww wwwwRRRRwwwwwwwwRRRRwwww wwwwRRRRwwwwwwwwRRRRwwww wwwwRRRRwwwwwwwwRRRRwwww wwwwwwwwRRRRRRRRwwwwwwww wwwwwwwwRRRRRRRRwwwwwwww wwwwwwwwRRRRRRRRwwwwwwww wwwwwwwwRRRRRRRRwwwwwwww wwwwRRRRwwwwwwwwRRRRwwww wwwwRRRRwwwwwwwwRRRRwwww wwwwRRRRwwwwwwwwRRRRwwww wwwwRRRRwwwwwwwwRRRRwwww RRRRwwwwwwwwwwwwwwwwRRRR RRRRwwwwwwwwwwwwwwwwRRRR RRRRwwwwwwwwwwwwwwwwRRRR RRRRwwwwwwwwwwwwwwwwRRRR
Score : 266 pts
Problem Statement
Takahashi is going to create mosaic art for the school festival.
First, Takahashi prepared a design draft in the form of a grid with H rows and W columns. Each cell of the grid is either # (filled) or . (blank).
Based on this design draft, Takahashi creates the mosaic art using the following procedure.
Step 1: Enlargement
Enlarge the design draft by a factor of K both vertically and horizontally. Specifically, replace each cell of the draft with a block of K rows and K columns filled with the same character, obtaining a grid of (H \times K) rows and (W \times K) columns consisting of # and ..
Step 2: Character Assignment
In the (H \times K) by (W \times K) grid obtained in Step 1, replace all # with character c_1 and all . with character c_2. Here, c_1 and c_2 are each a single character that is either a lowercase English letter (a–z) or an uppercase English letter (A–Z). It is possible that c_1 and c_2 are the same character.
Output the resulting mosaic art of (H \times K) rows and (W \times K) columns.
Constraints
- 1 \leq H \leq 100
- 1 \leq W \leq 100
- 1 \leq K \leq 50
- H, W, K are all integers
- c_1 is a single character that is either a lowercase English letter (
a–z) or an uppercase English letter (A–Z) - c_2 is a single character that is either a lowercase English letter (
a–z) or an uppercase English letter (A–Z) - c_1 and c_2 may be the same character
- S_i is a string of length W consisting of
#and.
Input
H W K c_1 c_2 S_1 S_2 \vdots S_H
- The first line contains the number of rows H, the number of columns W, and the enlargement factor K of the design draft, separated by spaces.
- The second line contains the character c_1 to replace
#and the character c_2 to replace., separated by a space. - Over the following H lines, the design draft is given. The i-th (1 \leq i \leq H) of these lines contains the string S_i corresponding to the i-th row from the top of the design draft. S_i is a string of length W consisting of
#and..
Output
Output the resulting mosaic art over (H \times K) lines. Each line is a string of length (W \times K).
Sample Input 1
3 3 2 X o #.# .#. #.#
Sample Output 1
XXooXX XXooXX ooXXoo ooXXoo XXooXX XXooXX
Sample Input 2
2 4 3 A B #..# .##.
Sample Output 2
AAABBBBBBAAA AAABBBBBBAAA AAABBBBBBAAA BBBAAAAAABBB BBBAAAAAABBB BBBAAAAAABBB
Sample Input 3
5 6 4 R w #....# .#..#. ..##.. .#..#. #....#
Sample Output 3
RRRRwwwwwwwwwwwwwwwwRRRR RRRRwwwwwwwwwwwwwwwwRRRR RRRRwwwwwwwwwwwwwwwwRRRR RRRRwwwwwwwwwwwwwwwwRRRR wwwwRRRRwwwwwwwwRRRRwwww wwwwRRRRwwwwwwwwRRRRwwww wwwwRRRRwwwwwwwwRRRRwwww wwwwRRRRwwwwwwwwRRRRwwww wwwwwwwwRRRRRRRRwwwwwwww wwwwwwwwRRRRRRRRwwwwwwww wwwwwwwwRRRRRRRRwwwwwwww wwwwwwwwRRRRRRRRwwwwwwww wwwwRRRRwwwwwwwwRRRRwwww wwwwRRRRwwwwwwwwRRRRwwww wwwwRRRRwwwwwwwwRRRRwwww wwwwRRRRwwwwwwwwRRRRwwww RRRRwwwwwwwwwwwwwwwwRRRR RRRRwwwwwwwwwwwwwwwwRRRR RRRRwwwwwwwwwwwwwwwwRRRR RRRRwwwwwwwwwwwwwwwwRRRR
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
高橋君はプログラミングコンテストのチーム編成を担当しています。候補者は N 人おり、 1 から N までの番号が付けられています。
各候補者 i は、自分が得意とするスキルの集合を非負整数 A_i のビット表現で表しています。高橋君はこの N 人の中からチームメンバーを選び、選んだメンバー全員のスキルをビットごとのオア(OR)で合わせたとき、チーム全体のスキルセットがちょうど目標値 K と一致するようにしたいと考えています。
高橋君はできるだけ多くの人をチームに入れたいと思っています。
候補者の空でない部分集合を選び、選んだ候補者のスキル値すべてのビットごとのオアがちょうど K と等しくなるようにするとき、選べる候補者の最大人数を求めてください。そのような部分集合が存在しない場合は -1 を出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq K \leq 10^{18}
- 0 \leq A_i \leq 10^{18}
- 入力はすべて整数である
入力
N K A_1 A_2 \ldots A_N
- 1 行目には、候補者の人数を表す N と、目標とするオアの値を表す K が、スペース区切りで与えられる。
- 2 行目には、各候補者のスキル値を表す A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
選んだ候補者のスキル値のビットごとのオアがちょうど K となるような空でない部分集合のうち、要素数が最大のものの要素数を 1 行で出力せよ。そのような部分集合が存在しない場合は -1 を出力せよ。
入力例 1
5 7 3 5 6 1 9
出力例 1
4
入力例 2
4 3 4 8 16 32
出力例 2
-1
入力例 3
10 15 1 2 4 8 3 5 15 6 16 14
出力例 3
9
Score : 300 pts
Problem Statement
Takahashi is in charge of forming teams for a programming contest. There are N candidates, numbered from 1 to N.
Each candidate i represents the set of skills they are proficient in as a bit representation of a non-negative integer A_i. Takahashi wants to select team members from these N people such that when the skills of all selected members are combined using bitwise OR, the team's overall skill set exactly matches the target value K.
Takahashi wants to include as many people as possible in the team.
Find the maximum number of candidates that can be selected from a non-empty subset of candidates such that the bitwise OR of all their skill values equals exactly K. If no such subset exists, output -1.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq K \leq 10^{18}
- 0 \leq A_i \leq 10^{18}
- All input values are integers.
Input
N K A_1 A_2 \ldots A_N
- The first line contains N, the number of candidates, and K, the target OR value, separated by a space.
- The second line contains the skill values A_1, A_2, \ldots, A_N of each candidate, separated by spaces.
Output
Output in one line the maximum number of elements in a non-empty subset of candidates whose bitwise OR of skill values equals exactly K. If no such subset exists, output -1.
Sample Input 1
5 7 3 5 6 1 9
Sample Output 1
4
Sample Input 2
4 3 4 8 16 32
Sample Output 2
-1
Sample Input 3
10 15 1 2 4 8 3 5 15 6 16 14
Sample Output 3
9
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 366 点
問題文
高橋君は自分の一族の家系図を調べています。一族には N 人の人物がおり、それぞれに 1 から N までの番号が付けられています。
この家系図において、一族の始祖である人物 1 を除くすべての人物には「親」が 1 人存在します。人物 i(2 \leq i \leq N)の親は人物 P_i です。この親子関係により、すべての人物は人物 1 を根とする根付き木を形成しています。
各人物 i には、その人物が残した遺産の価値 V_i が記録されています。
高橋君は、ある人物 X について、人物 X から親を繰り返したどって始祖(人物 1)に至るまでの経路上にいるすべての人物(人物 X 自身および人物 1 を含む)の遺産の価値の合計を「累積遺産」と呼ぶことにしました。
Q 個のクエリが与えられます。各クエリでは人物番号 X_j が指定されるので、その人物の累積遺産を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq V_i \leq 10^9(1 \leq i \leq N)
- 1 \leq P_i < i(2 \leq i \leq N)
- 1 \leq X_j \leq N(1 \leq j \leq Q)
- 入力はすべて整数である
入力
入力は以下の形式で標準入力から与えられる。
N Q V_1 V_2 \ldots V_N P_2 P_3 \ldots P_N X_1 X_2 \vdots X_Q
- 1 行目には、人物の数 N とクエリの数 Q が、スペース区切りで与えられる。
- 2 行目には、各人物の遺産の価値 V_1, V_2, \ldots, V_N が、スペース区切りで与えられる。
- 3 行目には、人物 2 から人物 N までの親の番号 P_2, P_3, \ldots, P_N が、スペース区切りで与えられる。ただし N = 1 のときは、この行には何も書かれていない(空行)。
- 続く Q 行のそれぞれに、各クエリで指定される人物番号が 1 つずつ与えられる。すなわち、そのうち j 行目(1 \leq j \leq Q)には X_j が与えられる。
出力
Q 行にわたって出力せよ。j 行目(1 \leq j \leq Q)には、j 番目のクエリで指定された人物 X_j の累積遺産を整数として出力せよ。
ans_1 ans_2 \vdots ans_Q
入力例 1
5 3 10 20 30 40 50 1 1 2 2 1 4 5
出力例 1
10 70 80
入力例 2
7 5 100 200 300 150 250 50 400 1 1 2 2 3 3 1 3 5 6 7
出力例 2
100 400 550 450 800
入力例 3
10 8 1000000000 500000000 300000000 200000000 100000000 800000000 600000000 400000000 250000000 150000000 1 1 2 2 3 3 4 5 6 1 4 7 8 9 10 3 6
出力例 3
1000000000 1700000000 1900000000 2100000000 1850000000 2250000000 1300000000 2100000000
Score : 366 pts
Problem Statement
Takahashi is investigating his family's genealogy. The family consists of N people, each numbered from 1 to N.
In this family tree, every person except person 1, who is the founding ancestor, has exactly one "parent." The parent of person i (2 \leq i \leq N) is person P_i. Through these parent-child relationships, all people form a rooted tree with person 1 as the root.
For each person i, the value V_i of the inheritance left by that person is recorded.
Takahashi defines the "cumulative inheritance" of a person X as the sum of the inheritance values of all people on the path from person X to the founding ancestor (person 1), obtained by repeatedly following the parent, including both person X themselves and person 1.
You are given Q queries. For each query, a person number X_j is specified. Find the cumulative inheritance of that person.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq V_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq P_i < i (2 \leq i \leq N)
- 1 \leq X_j \leq N (1 \leq j \leq Q)
- All input values are integers
Input
The input is given from standard input in the following format.
N Q V_1 V_2 \ldots V_N P_2 P_3 \ldots P_N X_1 X_2 \vdots X_Q
- The first line contains the number of people N and the number of queries Q, separated by a space.
- The second line contains the inheritance values V_1, V_2, \ldots, V_N of each person, separated by spaces.
- The third line contains the parent numbers P_2, P_3, \ldots, P_N for persons 2 through N, separated by spaces. When N = 1, this line is empty.
- Each of the following Q lines contains a single person number specified for each query. Specifically, the j-th of these lines (1 \leq j \leq Q) contains X_j.
Output
Output Q lines. On the j-th line (1 \leq j \leq Q), output the cumulative inheritance of person X_j specified in the j-th query as an integer.
ans_1 ans_2 \vdots ans_Q
Sample Input 1
5 3 10 20 30 40 50 1 1 2 2 1 4 5
Sample Output 1
10 70 80
Sample Input 2
7 5 100 200 300 150 250 50 400 1 1 2 2 3 3 1 3 5 6 7
Sample Output 2
100 400 550 450 800
Sample Input 3
10 8 1000000000 500000000 300000000 200000000 100000000 800000000 600000000 400000000 250000000 150000000 1 1 2 2 3 3 4 5 6 1 4 7 8 9 10 3 6
Sample Output 3
1000000000 1700000000 1900000000 2100000000 1850000000 2250000000 1300000000 2100000000
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 466 点
問題文
高橋君は冒険者です。ダンジョンを探索した結果、N 個の宝箱を発見しました。
i 番目の宝箱の重さは A_i キログラムで、価値は B_i です。
高橋君が持っているリュックサックには、重さの合計が M キログラム以下となるように宝箱を入れることができます。高橋君は N 個の宝箱の中から何個か(0個でもよい)を選んでリュックサックに入れて持ち帰ろうとしています。ただし、各宝箱は1個ずつしか存在しないため、同じ宝箱を複数回選ぶことはできません。
高橋君は、選んだ宝箱の重さの合計が M キログラム以下であるという制約のもとで、選んだ宝箱の価値の合計を最大化したいと考えています。価値の合計が最大となるような選び方を最適な選び方と呼ぶことにします。最適な選び方は複数存在する場合があります。
各宝箱 i (1 \leq i \leq N) について、宝箱 i を含むような最適な選び方が存在するかどうかを判定してください。
制約
- 1 \leq N \leq 1,000
- 1 \leq M \leq 3,000
- 1 \leq A_i \leq M (1 \leq i \leq N)
- 1 \leq B_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数である
入力
N M A_1 B_1 A_2 B_2 \vdots A_N B_N
- 1 行目には、宝箱の個数を表す整数 N と、リュックサックの容量を表す整数 M が、スペース区切りで与えられる。
- i + 1 行目 (1 \leq i \leq N) には、i 番目の宝箱の重さを表す整数 A_i と、価値を表す整数 B_i が、スペース区切りで与えられる。
出力
N 行出力してください。
i 行目には、宝箱 i を含むような最適な選び方が存在する場合は Yes を、存在しない場合は No を出力してください。
入力例 1
3 5 2 3 3 4 3 3
出力例 1
Yes Yes No
入力例 2
4 4 2 5 2 5 2 5 3 1
出力例 2
Yes Yes Yes No
入力例 3
6 8 3 5 4 6 5 7 2 3 1 1 6 8
出力例 3
Yes Yes Yes No Yes No
入力例 4
10 15 3 10 4 12 5 14 2 7 1 3 6 18 7 20 8 22 3 9 4 11
出力例 4
Yes Yes No Yes Yes Yes No No Yes No
入力例 5
1 1 1 1
出力例 5
Yes
Score : 466 pts
Problem Statement
Takahashi is an adventurer. After exploring a dungeon, he discovered N treasure chests.
The i-th treasure chest has a weight of A_i kilograms and a value of B_i.
Takahashi's backpack can hold treasure chests as long as their total weight is at most M kilograms. Takahashi plans to select some number of treasure chests (possibly zero) from the N chests to put in his backpack and carry home. However, since each treasure chest exists only once, the same chest cannot be selected multiple times.
Takahashi wants to maximize the total value of the selected treasure chests, subject to the constraint that the total weight of the selected chests is at most M kilograms. A selection that maximizes the total value is called an optimal selection. There may be multiple optimal selections.
For each treasure chest i (1 \leq i \leq N), determine whether there exists an optimal selection that includes treasure chest i.
Constraints
- 1 \leq N \leq 1,000
- 1 \leq M \leq 3,000
- 1 \leq A_i \leq M (1 \leq i \leq N)
- 1 \leq B_i \leq 10^9 (1 \leq i \leq N)
- All inputs are integers
Input
N M A_1 B_1 A_2 B_2 \vdots A_N B_N
- The first line contains an integer N representing the number of treasure chests and an integer M representing the capacity of the backpack, separated by a space.
- The (i + 1)-th line (1 \leq i \leq N) contains an integer A_i representing the weight of the i-th treasure chest and an integer B_i representing its value, separated by a space.
Output
Print N lines.
On the i-th line, print Yes if there exists an optimal selection that includes treasure chest i, and No otherwise.
Sample Input 1
3 5 2 3 3 4 3 3
Sample Output 1
Yes Yes No
Sample Input 2
4 4 2 5 2 5 2 5 3 1
Sample Output 2
Yes Yes Yes No
Sample Input 3
6 8 3 5 4 6 5 7 2 3 1 1 6 8
Sample Output 3
Yes Yes Yes No Yes No
Sample Input 4
10 15 3 10 4 12 5 14 2 7 1 3 6 18 7 20 8 22 3 9 4 11
Sample Output 4
Yes Yes No Yes Yes Yes No No Yes No
Sample Input 5
1 1 1 1
Sample Output 5
Yes