#P10051. [CCO 2022] Rainy Markets
[CCO 2022] Rainy Markets
Problem Description
There are bus stops, numbered . The -th bus stop can hold people.
For each , there is a sidewalk connecting bus stop and bus stop , with an open-air market in between. Market sells umbrellas, and each umbrella costs .
Currently, there are people in market , and all bus stops are empty.
Suddenly, it starts to rain. Each person in market must choose one of the following three options:
- Go to bus stop .
- Go to bus stop .
- 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 .
The second line contains space-separated integers , representing the capacity of bus stop .
The third line contains space-separated integers , representing the number of people in market .
The fourth line contains space-separated integers , representing the number of umbrellas sold in market .
Output Format
If everyone can end up either under an umbrella or in a bus stop, output lines:
- The first line should be
YES. - The second line should be an integer, the minimum total money spent on umbrellas.
- The next lines should each contain three space-separated integers. For market , they represent: the number of people who move to bus stop , the number of people who buy umbrellas, and the number of people who move to bus stop .
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 empty spots in the bus stops and no umbrellas for sale, but there are people in the market, so the answer is NO.
Explanation for Sample 2
The people in market go to bus stop , nobody buys an umbrella, and people go to bus stop .
In market , people go to bus stop , people stay and buy umbrellas, and people move to bus stop .
In total, umbrellas are bought, costing .
Constraints
For all testdata, , , .
| Subtask ID | Points | ||||
|---|---|---|---|---|---|
Translated by ChatGPT 5