Under construction

Still being built. Things may change

Boring Lectures

Time limit8sMemory limit512 MB

Summary
Given an array with point updates, after each update find the maximum sum of two elements that lie inside one window of K consecutive positions.
Level

Hard8 of 10

Topics
Segment tree, Sliding window, Array
Solved
No attempts yet

Problem

You have a schedule of NN upcoming lectures, and you may choose to attend some of them. The lectures are numbered from 11 to NN in chronological order. In the current schedule, the ii-th lecture has quality aia_i. Most of the lectures are boring, so you will attend only one group of KK consecutive lectures and skip the rest, so that you can sleep and prepare for programming contests. You do not like taking notes, so you can remember the content of only 22 of the lectures you attend. Choose the group of KK consecutive lectures and the 22 lectures you remember so that the sum of the qualities of those 22 lectures is as large as possible.

There are QQ changes to the schedule. The jj-th change is given by two values iji_j and xjx_j, which mean that the quality of the iji_j-th lecture becomes xjx_j. For each of the Q+1Q+1 versions of the schedule, find the maximum possible sum of lecture qualities.

Input

The first line contains three integers NN, KK, and QQ (2≤N≤1062 \le N \le 10^6, 2≤K≤N2 \le K \le N, 0≤Q≤1050 \le Q \le 10^5). The second line contains NN integers a1,…,aNa_1, \ldots, a_N (0≤ai≤1090 \le a_i \le 10^9). Each of the next QQ lines contains two integers iji_j and xjx_j (1≤ij≤N1 \le i_j \le N, 0≤xj≤1090 \le x_j \le 10^9).

Output

Print Q+1Q+1 lines. The jj-th line is the answer for the schedule after the first j−1j-1 changes have been applied.

Examples1

  1. Example 1

    Input
    4 3 1
    6 1 2 4
    1 3
    
    Expected output
    8
    6