City Bike

시간 제한2초메모리 제한2048 MB

요약
최대 c대를 실은 트럭이 n개의 대여소를 순서대로 방문하며 자전거를 싣고 내린다. 방문 후 가장 많은 대여소와 가장 적은 대여소의 자전거 수 차이를 최소로 만든다.
난이도

어려움10점 중 8점

유형
이분 탐색, 그리디, 누적 합, 배열
정답자
아직 제출이 없습니다

문제

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 cc bikes. Before it departs the bike center, it can choose to carry between 00 and cc bikes (both inclusive) as its initial load. The truck will then visit nn docking stations in order. Each docking station can dock at most dd 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 nn, dd, and cc (2≤n≤2⋅1052 ≤ n ≤ 2 \cdot 10^5, 1≤d,c≤1061 ≤ d, c ≤ 10^6), giving the number of docking stations, the capacity of the docking stations, and the capacity of the truck respectively.

The next nn lines each have a single integer between 00 and dd (both inclusive), giving the number of bikes that docking station ii initially has.

출력

Output a single integer, the smallest achievable difference between the maximum and minimum number of bikes at any of the docking stations.

예제1

  1. 예제 1

    입력
    4 7 3
    0
    7
    2
    5
    
    예상 출력
    1