시간 제한메모리 제한제출정답맞힌 사람정답 비율
1.5 초 1024 MB60231835.294%

문제

There are $N$ covered bus shelters, labelled $1, \ldots, N$. The $i^\text{th}$ bus shelter can fit $B_i$ people inside.

For each $i \in \{1, \ldots, N - 1\}$, there is a sidewalk connecting bus shelter $i$ to bus shelter $i + 1$, with an open-air market in the middle. The $i^\text{th}$ market has $U_i$ umbrellas for sale, each costing $\$1$.

Right now, the $i^\text{th}$ market has $P_i$ people inside, and every person is in a market so all the bus shelters are empty.

Suddenly, it starts raining, and everyone at market $i$ has to decide between three possibilities:

  • to go to bus shelter $i$;
  • to go to bus shelter $i + 1$; or
  • to stay and buy an umbrella.

If a person is unable to find a place in a bus shelter or buy an umbrella, they will get wet.

If everyone coordinates optimally, can they all stay dry? If so, what is the least amount of money they need to spend, and which bus shelter should each person move to?

입력

The first line of input contains an integer $N$.

The second line of input contains $N$ space-separated integers $B_i$ $(1 \le i \le N)$, the capacity of bus shelter $i$.

The third line of input contains $N - 1$ space-separated integers $P_i$ $(1 \le i \le N - 1)$, the number of people at market $i$.

The fourth line of input contains $N - 1$ space-separated integers $U_i$ $(1 \le i \le N - 1)$, the number of umbrellas for sale at market $i$.

출력

If every person can stay dry either under an umbrella or at a bus shelter, the output will be $N + 1$ lines:

  • the first line will contain the word YES.
  • the second line will contain the least amount of money necessary to spend on umbrellas
  • the next $N - 1$ lines will each contain three space-separated integers:
    • the number of people at market $i$ moving to bus shelter $i$
    • the number of people at market $i$ buying an umbrella
    • the number of people at market $i$ moving to bus shelter $i + 1$, where $1 \le i \le N - 1$.

If not every person can stay dry, the output will be one line containing the word NO.

If there are multiple possible correct outputs, any correct output will be accepted.

서브태스크

번호배점제한
15

$2 \le N \le 10^6$, $0 \le B_i \le 2 \cdot 10^9$, $0 \le P_i \le 10^9$, $U_i = 0$

25

$2 \le N \le 2\,000$, $0 \le B_i \le 400$, $0 \le P_i \le 200$, $0 \le U_i \le 200$

36

$2 \le N \le 4\,000$, $0 \le B_i \le 4\,000$, $0 \le P_i \le 2\,000$, $0 \le U_i \le 2\,000$

49

$2 \le N \le 10^6$, $0 \le B_i \le 2 \cdot 10^9$, $0 \le P_i \le 10^9$, $0 \le U_i \le 10^9$

예제 입력 1

3
10 15 10
20 20
0 0

예제 출력 1

NO

There are $35$ spots available at bus shelters and no umbrellas available, but there are $40$ people in the markets.

예제 입력 2

3
10 15 10
20 20
0 11

예제 출력 2

YES
5
10 0 10
5 5 10

Looking at market $1$, $10$ people will go to bus shelter $1$, no one will buy an umbrella, and $10$ people will go to bus shelter $2$.

Looking at market $2$, $5$ people will go to bus shelter $2$, $5$ people will stay and buy an umbrella, and $10$ people will move to bus shelter $3$.

In total, $5$ umbrellas were purchased, which costs $\$5$.

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.