Back
Close
  • 41

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

Statement

 Goal

At the company Helping Around Breaks (HAB), a certain number of counters (nc) is operating to help visitors. Each counter is manned by an employee with a certain efficiency. A number of visitors (nv) visits HAB with a request that needs some minutes of helptime at any of the counters. The eventual time used for resolving that request is a result of the helptime divided by the efficiency at a particular counter. Each time when an employee is finished helping one visitor, it can help the next visitor in line. However, after a number of minutes worktime, an employee will take a 10 minute break - as long as they are not in the middle of helping a visitor.

You need to output how many visitors each counter has helped, and how many breaks are taken at every counter.

Rules
- When multiple counters are available, the first visitor in line will go to the first available counter, the second to the second, etcetera.
- When a counter is available, it will instantly start with either helping the first visitor waiting in line, or (if worktime minutes have passed) have a 10 minute break.
- All counters take new visitors or breaks until there are no visitors left waiting, and finish with any visitor or break they started on. A counter will never start a break at the same moment the last visitor starts being served at another counter.
- After a break, the employee will work for at least worktime minutes until the next break.
If, with a worktime of 30 minutes, a counter is helping a person for 60 minutes, it still deserves only one break. After the break, it again has to work 30 minutes (or more) until the next break time.

Example
There are 2 operating counters with efficiency 2 and 1, and 3 visitors with helptime 40, 30 and 10 minutes, worktime is 20 minutes. The first visitor is helped at the first counter in 40/2 = 20 minutes. The second visitor is helped at the second counter in 30 minutes. The first counter has worked 20 minutes, and therefore takes a 10 minute break. At minute 30, after the break, the first counter helps the third visitor. There are no more visitors in line, so the employee at the second counter can go home instead of taking a break. At the end, the two counters have helped 2 and 1 visitors, and have taken 1 and 0 breaks.

Note on rounding: any calculations should not be rounded. For example, helptime of 15 minutes and efficiency of 2 leads to 7.5 minutes of work - not 7 or 8 minutes.
Input
Line 1: integer worktime: the number of minutes a counter should work at least for every 10 minute break time.
Line 2: integer nc: number of counters in use.
Line 3: nc space separated floats; per counter the efficiency.
Line 4: integer nv: number of visitors.
Line 5: nv space separated integers; per visitor the helptime in minutes.
Output
Line 1: nc space separated integers: per counter, the number of persons helped by that counter.
Line 2: nc space separated integers: per counter, the number of breaks taken.
Constraints
20 <= worktime <= 180
0 < nc <= 15
0 < efficiency <= 2
0 < nv <= 30
0 < helptime <= 180
Example
Input
100
2
1 1
5
40 16 12 8 4
Output
1 4
0 0

A higher resolution is required to access the IDE