City Bike
시간 제한2초메모리 제한2048 MB
최대 c대를 실은 트럭이 n개의 대여소를 순서대로 방문하며 자전거를 싣고 내린다. 방문 후 가장 많은 대여소와 가장 적은 대여소의 자전거 수 차이를 최소로 만든다.
문제
City bike is a popular commute method. But it is sometimes frustrating that some bike docking stations have few bikes, while others are almost full and have few empty docks. The bike company regularly sends trucks to relocate bikes to mitigate such issues.
A truck is about to depart the bike center to start a bike relocation trip. The truck can carry at most bikes. Before it departs the bike center, it can choose to carry between and bikes (both inclusive) as its initial load. The truck will then visit docking stations in order. Each docking station can dock at most bikes. Initially, some bikes are already docked at each docking station. At each docking station the truck can load or unload any number of bikes as long as they do not exceed the capacity of the truck or the docking station. By the end of the trip the truck does not have to carry the same number of bikes as its initial load. The goal of the bike relocation trip is to minimize the difference between the maximum and minimum number of bikes at any of the docking stations.
What is the smallest difference that can be achieved?
입력
The first line of input contains three integers , , and (, ), giving the number of docking stations, the capacity of the docking stations, and the capacity of the truck respectively.
The next lines each have a single integer between and (both inclusive), giving the number of bikes that docking station initially has.
출력
Output a single integer, the smallest achievable difference between the maximum and minimum number of bikes at any of the docking stations.