Knapsack Collection
Time limit4sMemory limit512 MB
Over every starting slot, find the min, max, and average time to collect all bags from a rotating carousel when each pickup takes t units.
- Level
Medium6 of 10
- Topics
- Sorting, Prefix sum, Math
- Solved
- No attempts yet
Problem
Gerald welcomes the teams arriving for a programming contest at the airport. One of his duties is to stand at the luggage carousel and collect every knapsack the teams bring. Gerald is a lazy person, so he stays at one position of the carousel and waits for bags to pass by so he can pick them up.
The carousel consists of luggage slots, numbered in ascending order from to . The carousel is cyclic, so slots and lie side by side as well. It turns so that if Gerald stands in front of slot at some point in time, he stands in front of slot one time unit later.
In the beginning Gerald prepares a huge baggage cart at some slot and stands there to wait for luggage. When a knapsack arrives in front of him, he needs time units to take it and put it on the cart. After these time units he is ready to pick up another knapsack. As long as knapsacks remain on the carousel, Gerald takes the next one to arrive at his position once he is ready.
Gerald wonders how his choice of position changes the time the task takes. There are slots that can appear in front of him after the preparation. Compute the minimum, the maximum, and the average time needed to pick up all knapsacks, taken over those slots. Time starts when he has prepared the cart at some slot and ends when he has put the last knapsack on the cart.
Input
The first line contains three integers , and (, , ), where is the number of knapsacks to pick up, is the number of slots of the carousel, and is the number of time units Gerald needs to take one knapsack from the carousel and put it on the cart.
The second line contains integers (), the slots of the knapsacks.
Several knapsacks may be stacked on top of each other in the same slot, but Gerald still picks up only one knapsack at a time.
Output
Print three lines: the minimum time, the maximum time, and the average time over all starting slots.
Print the average as a reduced fraction p/q, where and the greatest common divisor of and is . When the average is an integer, print it with denominator , for example 16/1.