Boring Lectures
Time limit8sMemory limit512 MB
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 upcoming lectures, and you may choose to attend some of them. The lectures are numbered from to in chronological order. In the current schedule, the -th lecture has quality . Most of the lectures are boring, so you will attend only one group of 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 of the lectures you attend. Choose the group of consecutive lectures and the lectures you remember so that the sum of the qualities of those lectures is as large as possible.
There are changes to the schedule. The -th change is given by two values and , which mean that the quality of the -th lecture becomes . For each of the versions of the schedule, find the maximum possible sum of lecture qualities.
Input
The first line contains three integers , , and (, , ). The second line contains integers (). Each of the next lines contains two integers and (, ).
Output
Print lines. The -th line is the answer for the schedule after the first changes have been applied.