Rainy Markets
면접 대비시간 제한1.5초메모리 제한1024 MB
일직선 위 시장의 사람들이 양옆 대피소로 이동하거나 우산을 사서 모두 젖지 않게 하면서, 우산 구매 비용을 최소로 하는 각 시장의 이동 인원을 구한다.
문제
There are covered bus shelters, labelled . The bus shelter can fit people inside.
For each , there is a sidewalk connecting bus shelter to bus shelter , with an open-air market in the middle. The market has umbrellas for sale, each costing 1$.
Right now, the market has people inside, and every person is in a market so all the bus shelters are empty.
Suddenly, it starts raining, and everyone at market has to decide between three possibilities:
- to go to bus shelter ;
- to go to bus shelter ; 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 .
The second line of input contains space-separated integers , the capacity of bus shelter .
The third line of input contains space-separated integers , the number of people at market .
The fourth line of input contains space-separated integers , the number of umbrellas for sale at market .
출력
If every person can stay dry either under an umbrella or at a bus shelter, the output will be 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 lines will each contain three space-separated integers:
- the number of people at market moving to bus shelter
- the number of people at market buying an umbrella
- the number of people at market moving to bus shelter , where .
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.