#SGM0000014. Truy vấn tổng đoạn con (Subarray Sum Queries)
Truy vấn tổng đoạn con (Subarray Sum Queries)
Subarray Sum Queries
Source: CSES
Version: Phuoc Hung OJ Extended
You are given an array of integers and point updates. An update gives and assigns . After each update, print the maximum contiguous subarray sum of the whole array.
The empty subarray with sum is allowed.
Input
The first line contains .
The second line contains .
Each of the next lines contains .
Output
After every update, print the maximum subarray sum.
Subtasks
- Subtask 1 — 20%: , .
- Subtask 2 — 30%: , .
- Subtask 3 — 50%: , .
Examples
Input
5 3
1 2 -3 5 -1
2 6
3 1
2 -2
Output
9
13
6
Explanation
The sample follows the operations exactly; each printed line corresponds to a query that requires output.