Time Limit: 5 sec / Memory Limit: 1024 MB
配点 : 100 点
問題文
1 から N までの番号のついた N 本の旗があります. これらの旗を,数直線状に設置します.
旗 i は,座標 X_i または 座標 Y_i に設置することができます. ただし,どの 2 つの旗についても,その間の距離が D 以上である必要があります.
N 本の旗を設置することが可能かどうか判定し,可能であるならば,実際に置き方を 1 つ示してください.
制約
- 1 \leq N \leq 1000
- 0 \leq D \leq 10^9
- 0 \leq X_i < Y_i \leq 10^9
- 入力される数は全て整数である.
入力
入力は以下の形式で標準入力から与えられる.
N D X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
出力
N 本の旗を設置することが不可能な場合,No
と出力せよ.
可能な場合,まず Yes
と出力せよ.
そして,続いて N 行出力せよ.
このうち i 行目には,旗 i を設置する座標を出力せよ.
入力例 1
3 2 1 4 2 5 0 6
出力例 1
Yes 4 2 0
入力例 2
3 3 1 4 2 5 0 6
出力例 2
No
Score : 100 points
Problem Statement
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print such a configulation.
Constraints
- 1 \leq N \leq 1000
- 0 \leq D \leq 10^9
- 0 \leq X_i < Y_i \leq 10^9
- All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N D X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
Output
Print No
if it is impossible to place N flags.
If it is possible, print Yes
first.
After that, print N lines. i-th line of them should contain the coodinate of flag i.
Sample Input 1
3 2 1 4 2 5 0 6
Sample Output 1
Yes 4 2 0
Sample Input 2
3 3 1 4 2 5 0 6
Sample Output 2
No