City Bike
Time limit2sMemory limit2048 MB
A truck with capacity c moves bikes among n stations, each holding at most d bikes. Find the smallest possible gap between the fullest and emptiest station.
- Level
Medium7 of 10
- Topics
- Greedy, Binary search, Simulation
- Solved
- No attempts yet
Problem
City bikes are a popular way to commute. Some docking stations have only a few bikes while others are almost full with few empty docks, which is frustrating for riders. The bike company regularly sends trucks to move bikes between stations to ease this imbalance.
A truck is about to leave the bike center to start a relocation trip. The truck can carry at most bikes. Before it departs, it may choose an initial load of anywhere from to bikes, both inclusive. The truck then visits docking stations in order. Each docking station can hold at most bikes, and some bikes are already docked at each station at the start. At each station, the truck may load or unload any number of bikes, as long as the truck does not exceed its capacity or the station does not exceed its capacity . The truck does not have to end the trip with the same number of bikes as its initial load. The goal is to minimize the difference between the maximum and minimum number of bikes at any station.
What is the smallest difference that can be achieved?
Input
The first line contains three integers , , and (, ), the number of docking stations, the capacity of each docking station, and the capacity of the truck. Each of the next lines contains a single integer between and , both inclusive, the number of bikes that docking station initially has.
Output
Output a single integer, the smallest achievable difference between the maximum and minimum number of bikes at any docking station.