Under construction

Still being built. Things may change

Coin Quiz

Interview

Time limit1sMemory limit1024 MB

Summary
Pick a threshold b that empties cells holding at most b coins so every k consecutive cells have at least m empty ones, maximizing leftover coins minus b.
Level

Medium6 of 10

Topics
Binary search, Sliding window, Prefix sum
Solved
No attempts yet

Statement

The rules of a new TV quiz are as follows. There are nn cells in a row, numbered from 11 to nn. Cell ii contains aia_i coins.

A player may choose an integer bb and pay bb coins. Then the host takes the coins from every cell that holds at most bb coins, and those cells become empty. After that, among any kk consecutive cells there must be at least mm empty cells. Then the player takes all coins left on the board. If the player takes aa coins in total, the prize is a−ba-b.

Find the maximum prize the player can guarantee.

Input

The first line contains integers nn, kk, and mm (1≤m<k≤n≤2000001 \le m < k \le n \le 200000).

The second line contains nn integers aia_i (1≤ai≤1091 \le a_i \le 10^9).

Output

Print one integer: the maximum prize the player can guarantee.

Hint

In the first example, the player chooses b=5b = 5. After the coins are removed from the cells that hold at most 55 coins, the cells contain [0,7,0,0,0,9,0,6][0, 7, 0, 0, 0, 9, 0, 6]. The player takes 2222 coins from the cells. Counting the 55 coins paid earlier, the prize is 1717.

In the second example, so that every two consecutive cells contain at least one empty cell, the player must choose b=2b = 2. After that no coins remain, and the prize is negative: −2-2.

Examples2

  1. Example 1

    Input
    8 4 2
    3 7 4 1 5 9 2 6
    
    Expected output
    17
    
  2. Example 2

    Input
    5 2 1
    2 2 2 2 2
    
    Expected output
    -2