Statues

시간 제한2초메모리 제한2048 MB

요약
맨해튼 거리로 주어진 각 구간 길이와 마지막 좌표가 주어질 때, 격자 위 경로가 존재하는지 판정하고 하나를 출력한다.
난이도

보통10점 중 7점

유형
그리디, 수학, 기하, 구현
정답자
아직 제출이 없습니다

문제

The mayor of a city wants to place nn statues at intersections around the city. The intersections in the city are at all points (x,y)(x, y) with integer coordinates. Distances between intersections are measured using Manhattan distance, defined as follows:

distance((x_1,y_1),(x_2,y_2))=∣x_1−x_2∣+∣y_1−y_2∣\text{distance}((x\_1, y\_1),(x\_2, y\_2)) = |x\_1 - x\_2| + |y\_1 - y\_2|.

The city council has provided the following requirements for the placement of the statues:

  • The first statue is placed at (0,0)(0, 0);
  • The nn-th statue is placed at (a,b)(a, b);
  • For i=1,…,n−1i = 1, \dots , n - 1, the distance between the ii-th statue and the (i+1)(i + 1)-th statue is d_id\_i.

It is allowed to place multiple statues at the same intersection.

Help the mayor find a valid arrangement of the nn statues, or determine that it does not exist.

입력

The first line contains an integer nn (3≤n≤503 ≤ n ≤ 50) — the number of statues.

The second line contains two integers aa and bb (0≤a,b≤1090 ≤ a, b ≤ 10^9) — the coordinates of the intersection where the nn-th statue must be placed.

The third line contains n−1n - 1 integers d_1,…,d_n−1d\_1, \dots , d\_{n-1} (0≤d_i≤1090 ≤ d\_i ≤ 10^9) — the distance between the ii-th statue and the (i+1)(i + 1)-th statue.

출력

Print YES if there is a valid arrangement of the nn statues. Otherwise, print NO.

If there is a valid arrangement, print a valid arrangement in the following nn lines. The ii-th of these lines must contain two integers x_ix\_i and y_iy\_i — the coordinates of the intersection where the ii-th statue is placed. You can print any valid arrangement if multiple exist.

예제2

  1. 예제 1

    입력
    3
    5 8
    9 0
    
    예상 출력
    NO
    
  2. 예제 2

    입력
    4
    10 6
    7 8 5
    
    예상 출력
    YES
    0 0
    6 -1
    11 2
    10 6