Get Them All
Time limit1sMemory limit128 MB
Simulate the vehicle dispatch and routing rules to find when all contestants reach the contest site, or how many arrive by the time limit.
- Level
Medium7 of 10
- Topics
- Simulation, Implementation, Queue
- Solved
- No attempts yet
Problem
To make sure the contestants can easily reach the regional contest site, the organizers have prepared several robot-driven vehicles. The vehicles visit predetermined junctions and carry the contestants waiting there to the contest. A computer-controlled Transportation Center (TC) decides the number of seats of each vehicle and the time at which each vehicle first leaves the contest site.
Whenever a new vehicle is needed, a request is sent to the TC. As long as the seat count stays above 3, each new vehicle has fewer seats than the previous one: the -th vehicle has seats (). The first vehicle leaves the contest site exactly at 8:00am (time ). When the TC receives a request for a new vehicle, it prepares one, and exactly seconds after receiving the request that vehicle leaves the contest site. If several requests arrive at the same time, only one of them is honored.
At junction each vehicle performs the tasks below. If more than one vehicle is at at the same time, they perform the tasks in order of their service time: the vehicle with the longest service time goes first. A vehicle's service time is the current time minus the time at which that vehicle first left the contest site (junction ).
-
If (the contest site), every contestant in the vehicle gets off. Otherwise the vehicle picks up as many contestants as it can (until the vehicle is full or no contestant is left at junction ).
-
If, after that, any contestant is still left at junction (), the vehicle sends a request for a new vehicle to the TC.
-
Finally the vehicle starts moving toward the next junction , which the robot-driver chooses as follows (this also applies at junction ):
- If the vehicle is full, .
- Otherwise, if no other vehicle has left junction yet, .
- Otherwise, if that value is different from .
- Otherwise, .
- (Here is the "next junction" chosen by the most recent vehicle to leave junction .)
The three tasks above happen instantly (in seconds). The time needed to travel from each junction to every other junction is given. All contestants have reached a suitable junction by 8:00am and do not leave until some vehicle picks them up. Given the number of contestants waiting at each junction and a time limit, determine the time at which everyone reaches the contest, or how many contestants have reached the contest by the time limit.
Input
The input consists of several datasets. Each dataset has the following form:
- A line with the name of the set (2 to 20 alphanumeric characters).
- A line with three positive integers , , and ().
- Then lines, each with integers. The -th line () gives the time (in seconds) needed to travel from junction to every other junction (all except ), listed in order of destination index .
- Then lines, each with one non-negative integer. The -th line () is the number of contestants waiting at junction .
- The last line of the dataset is the time limit (in seconds, less than ).
Integers on the same line are separated by exactly one space. The total number of contestants is at most .
The end of the input is marked by a line containing only TheEnd.
Output
For each set, print two lines. The first line is the name of the set exactly as it appears in the input. On the second line, if the time needed to bring all contestants to the contest does not exceed the given time limit, print that time (in seconds) as <time> seconds needed. Otherwise, print the number of contestants that reached the contest by the time limit as <count> contestants reached.