Under construction

Still being built. Things may change

TOO EASY Cookie Run

Interview

Time limit2sMemory limit1024 MB

Summary
Find the smallest X added to every stage so that at least K contiguous sections have a sum of at least M.
Level

Medium6 of 10

Topics
Binary search, Two pointers, Prefix sum
Solved
No attempts yet

Problem

Cookie Run is a popular game in which a cookie character runs through a map of N stages to score points.

Soo Young, the map designer for Cookie Run, was preparing a new map patch for Children's Day. After she finished building an attractive map and testing it for the last time the day before the patch, she realized the map was designed to be too easy.

The map follows these rules.

  • Each stage has a difficulty level A_0,A_1,A_2,...,A_N−1A\_0, A\_1, A\_2, ..., A\_{N-1}. The higher the difficulty, the harder the stage is to pass.
  • If the sum of consecutive stages' difficulty levels is at least MM, the section is called an interesting section. That is, if A_i+A_i+1+...+A_j≥MA\_i + A\_{i+1} + ... + A\_j \geq M, the section (i,j)(i, j) is an interesting section.
  • The map must have at least KK interesting sections.

In other words, let TT be the number of pairs (i,j)(i, j) with 0≤i≤j≤N−10 \le i \le j \le N-1 and A_i+...+A_j≥MA\_i + ... + A\_j \geq M. Then T≥KT \geq K must hold.

Soo Young requested help from participants of the KAIST RUN Spring Contest. All she can do is add difficulty XX to all stages at once to make the map harder. Find the smallest non-negative integer XX that satisfies these conditions.

Input

The first line contains three space-separated integers NN, MM, and KK.

The second line contains NN space-separated integers A_0,A_1,⋯ ,A_N−1A\_{0}, A\_{1}, \cdots, A\_{N-1}.

Output

Print a single non-negative integer, the smallest XX that satisfies the conditions.

You can assume that at least one non-negative integer XX exists that satisfies the given conditions.

Constraints

  • 1≤N≤100 0001 \le N \le 100\,000
  • 1≤M≤10181 \le M \le 10^{18}
  • 1≤K≤N(N+1)21 \le K \le \frac{N (N+1)}{2}
  • 0≤A_i≤1090 \le A\_{i} \le 10^9 (0≤i≤N−1)(0 \le i \le N-1)

Examples3

  1. Example 1

    Input
    3 20 5
    4 0 4
    
    Expected output
    16
    
  2. Example 2

    Input
    5 30 4
    1 2 3 4 5
    
    Expected output
    6
    
  3. Example 3

    Input
    4 32 4
    8 7 5 9
    
    Expected output
    9