#P11359. [eJOI 2023] Team Building
[eJOI 2023] Team Building
Problem Description
You need to gather a team of people. The -th person has an ability value . You may add people to your team one by one, in any order.
In your team, each person has two additional attributes: Star Talk and Cuteness. Adding a person consists of three steps:
- This person enters the team, and both their Star Talk and Cuteness are .
- For all remaining people, their Star Talk increases by their own Cuteness.
- For all remaining people, their Cuteness increases by the ability value of the newly added person.
In the end, the total Star Talk value of your team is defined as the sum of everyone’s Star Talk values. You need to maximize the total Star Talk value.
For example, if you add people with ability values in this order, the changes of everyone’s attributes are as follows:
| Action | Star Talk | Cuteness |
|---|---|---|
| Add the first person | ||
| Add the second person | ||
| Update Star Talk | ||
| Update Cuteness | ||
| Add the third person | ||
| Update Star Talk | ||
| Update Cuteness | ||
| Add the fourth person | ||
| Update Star Talk | ||
| Update Cuteness | ||
At this point, the total Star Talk value is . However, if you change the order to , you can get .
You also need to process modifications. Each modification changes the ability value of person to . You need to output the maximum total Star Talk value after each modification. The modifications are not independent, meaning each modification is kept for the next one.
Input Format
The first line contains two integers .
The second line contains integers .
The next lines each contain two integers .
Output Format
Output lines. Each line contains one integer, representing the answer for the initial sequence and after each modification.
4 2
2 0 2 3
2 4
4 0
10
14
12
Hint
Sample Explanation
The optimal plan for the original sequence has already been given in the statement.
After the first modification, the sequence becomes .
After the second modification, the sequence becomes .
Constraints
This problem uses bundled testdata.
- Subtask 1 (11 pts): , .
- Subtask 2 (19 pts): .
- Subtask 3 (15 pts): .
- Subtask 4 (6 pts): .
- Subtask 5 (9 pts): .
- Subtask 6 (12 pts): .
- Subtask 7 (10 pts): the difference between each modification and the original number is at most .
- Subtask 8 (18 pts): no special restrictions.
For of the data, it is guaranteed that , , , , .
Translated by ChatGPT 5