#P6717. [CCO 2018] Boring Lectures

[CCO 2018] Boring Lectures

Description

There is a sequence of length NN, where the ii-th number is aia_i.

There are QQ modifications. In the jj-th modification, the number at position iji_j is changed to xjx_j.

You need to find, for the initial sequence and after each modification, the maximum possible value of the sum of the largest and second largest elements among all consecutive subarrays of length KK.

Input Format

The first line contains three integers N,K,QN, K, Q, as described above.
The second line contains NN integers aia_i, the sequence.
The next QQ lines each contain two integers ij,xji_j, x_j, representing one modification.

Output Format

Output Q+1Q+1 lines. The jj-th line represents the answer after the (j1)(j-1)-th modification. The first line represents the answer before any modifications.

4 3 1
6 1 2 4
1 3
8
6

Hint

Sample Explanation

For Sample 11.

  • Before any modification, we choose [1,3][1,3], and the sum is 6+2=86+2=8.
  • After the first modification, we choose [2,4][2,4], and the sum is 2+4=62+4=6.

Constraints

For 100%100\% of the testdata, 2N1062 \le N \le 10^6, 2KN2 \le K \le N, 0Q1050 \le Q \le 10^5, 0ai1090 \le a_i \le 10^9, 1ijN1 \le i_j \le N, 0xj1090 \le x_j \le 10^9.
For 20%20\% of the testdata, Q=0Q=0.
For another 40%40\% of the testdata, N104N \le 10^4.

Notes

Translated from Canadian Computing Olympiad 2018 Day 2 B Boring Lectures

Translated by ChatGPT 5