CCO '22 P2 - Rainy Markets
View as PDFCanadian Computing Olympiad: 2022 Day 1, Problem 2
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 
.
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?
Input Specification
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 
.
| Marks Awarded | Number of bus shelters | Maximum people/bus shelters | Maximum people/market | Maximum umbrellas/market | 
|---|---|---|---|---|
Output Specification
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
.
 
 - the number of people at market 
 
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.
Sample Input 1
3
10 15 10
20 20
0 0
Output for Sample Input 1
NO
Explanation of Output for Sample Input 1
There are  spots available at bus shelters and no umbrellas available, but there are 
 people in the markets.
Sample Input 2
3
10 15 10
20 20
0 11
Possible Output for Sample Input 2
YES
5
10 0 10
5 5 10
Explanation of Output for Sample Input 2
Looking at market , 
 people will go to bus shelter 
, no one will buy an umbrella, and 
 people will go to bus shelter 
.
Looking at market , 
 people will go to bus shelter 
, 
 people will stay and buy an umbrella, and 
 people will move to bus shelter 
.
In total,  umbrellas were purchased, which costs 
.
Comments