#P10051. [CCO 2022] Rainy Markets

    ID: 11405 远端评测题 1500ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP贪心2022Special JudgeCCO(加拿大)

[CCO 2022] Rainy Markets

Problem Description

There are NN bus stops, numbered 1,,N1, \ldots, N. The ii-th bus stop can hold BiB_{i} people.

For each i{1,,N1}i \in \{1, \ldots, N-1\}, there is a sidewalk connecting bus stop ii and bus stop i+1i+1, with an open-air market in between. Market ii sells UiU_{i} umbrellas, and each umbrella costs 11.

Currently, there are PiP_{i} people in market ii, and all bus stops are empty.

Suddenly, it starts to rain. Each person in market ii must choose one of the following three options:

  • Go to bus stop ii.
  • Go to bus stop i+1i+1.
  • Stay and buy an umbrella.

If a person cannot get into a bus stop or cannot buy an umbrella, they will get wet.

You need to determine whether, under an optimal arrangement, it is possible to ensure that nobody gets wet. If it is possible, you must output the minimum total money that needs to be spent, and where people from each market should go.

Input Format

The first line contains an integer NN.

The second line contains NN space-separated integers Bi (1iN)B_{i}\ (1 \leq i \leq N), representing the capacity of bus stop ii.

The third line contains N1N-1 space-separated integers Pi (1iN1)P_{i}\ (1 \leq i \leq N-1), representing the number of people in market ii.

The fourth line contains N1N-1 space-separated integers Ui (1iN1)U_{i}\ (1 \leq i \leq N-1), representing the number of umbrellas sold in market ii.

Output Format

If everyone can end up either under an umbrella or in a bus stop, output N+1N+1 lines:

  • The first line should be YES.
  • The second line should be an integer, the minimum total money spent on umbrellas.
  • The next N1N-1 lines should each contain three space-separated integers. For market i (1iN1)i\ (1 \leq i \leq N-1), they represent: the number of people who move to bus stop ii, the number of people who buy umbrellas, and the number of people who move to bus stop i+1i+1.

If there are multiple valid solutions, you may output any one of them.

Otherwise, output a single line NO.

3
10 15 10
20 20
0 0
NO
3
10 15 10
20 20
0 11
YES
5
10 0 10
5 5 10

Hint

Explanation for Sample 1

There are 3535 empty spots in the bus stops and no umbrellas for sale, but there are 4040 people in the market, so the answer is NO.

Explanation for Sample 2

The 1010 people in market 11 go to bus stop 11, nobody buys an umbrella, and 1010 people go to bus stop 22.

In market 22, 55 people go to bus stop 22, 55 people stay and buy umbrellas, and 1010 people move to bus stop 33.

In total, 55 umbrellas are bought, costing 55.

Constraints

For all testdata, 2N1062 \leq N \leq 10^{6}, 0Bi21090 \leq B_{i} \leq 2 \cdot 10^{9}, 0Pi,Ui1090 \leq P_{i}, U_{i} \leq 10^{9}.

Subtask ID Points NN BB PP UU
11 2020 2N1062 \leq N \leq 10^{6} 0Bi21090 \leq B_{i} \leq 2 \cdot 10^{9} 0Pi1090 \leq P_{i} \leq 10^{9} Ui=0U_{i} = 0
22 2N20002 \leq N \leq 2000 0Bi4000 \leq B_{i} \leq 400 0Pi2000 \leq P_{i} \leq 200 0Ui2000 \leq U_{i} \leq 200
33 2424 2N40002 \leq N \leq 4000 0Bi40000 \leq B_{i} \leq 4000 0Pi20000 \leq P_{i} \leq 2000 0Ui20000 \leq U_{i} \leq 2000
44 3636 2N1062 \leq N \leq 10^{6} 0Bi21090 \leq B_{i} \leq 2 \cdot 10^{9} 0Pi1090 \leq P_{i} \leq 10^{9} 0Ui1090 \leq U_{i} \leq 10^{9}

Translated by ChatGPT 5