#FT0000058. Tổng thành tích cao nhất (Best Performances)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng thành tích cao nhất (Best Performances)
Best Performances
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of nonnegative integers, initially all zero, and a fixed integer . After every assignment, print the sum of exactly the largest values currently in the entire sequence. Equal values count separately as many times as they appear.
Each update means assign rather than add . Print the new top- sum immediately after applying each update.
Input
- Line 1: integers for array length, number of largest values, and update count.
- Next lines: update contains integers assigning the new value at position .
Output
Print lines; line gives the sum of the largest array entries after update .
Subtasks
Subtask 1 (20 points):
- ; ; , for every update.
Subtask 2 (30 points):
- ; ; , for every update.
Subtask 3 (50 points):
- ; ; , for every update.
Examples
Examples 1
Input
4 2 10
1 5
2 1
3 3
4 2
2 10
1 0
4 0
3 1
2 0
3 0
Output
5
6
8
8
15
13
13
11
1
0
Explanation
Initially . After updates 1–4, the top-two sums are respectively 5, 6, 8, 8. Update 5 makes the array with top-two sum 15. Applying the remaining assignments yields sums 13,13,11,1,0 in sequence.
Examples 2
Input
3 3 4
2 5
1 4
3 7
2 0
Output
5
9
16
11
Explanation
Since , the top-three sum is the sum of the entire array. The states are , , , and , yielding 5,9,16,11.
The updates set , , , and finally . Because all three elements are included in every top- sum, sorting them in descending order does not change the sum. Adding the entries of each resulting state yields the four displayed outputs.