#HK4016. 「eJOI2023」Team Building
「eJOI2023」Team Building
Description
You aim to assemble a team of programmers. You've already scouted them and assessed that the skill level of the -th individual () is represented by the nonnegative integer . You've realized that what truly matters is the order in which you hire them.
Each programmer is characterized by two additional integer values: workrate and motivation, both of which are upon their arrival but can increase after hiring new team members. When a new programmer is hired, the following events occur in the given order:
- The new programmer joins the team with workrate and motivation initialized to .
- The workrate of each other previously hired programmer is increased by their own motivation value.
- The motivation of each other previously hired programmer is increased by the skill level of the new hire.
The strength of the team is determined afterwards by the sum of the workrates of all the team members. Your objective is to calculate the maximum attainable team strength by optimizing the order of hiring.
For example, if you hire programmers with skill levels in this order, the hiring process will affect their values as follows:
| Event | Workrates | Motivations |
|---|---|---|
| Hiring with skill 0 | 0 | 0 |
| Hiring with skill 2 | 0 0 | 0 0 |
| Workrates update | 0 0 | 0 0 |
| Motivations update | 0 0 | 2 0 |
| Hiring with skill 2 | 0 0 0 | 2 0 0 |
| Workrates update | 2 0 0 | 2 0 0 |
| Motivations update | 2 0 0 | 4 2 0 |
| Hiring with skill 3 | 2 0 0 0 | 4 2 0 0 |
| Workrates update | 6 2 0 0 | 4 2 0 0 |
| Motivations update | 6 2 0 0 | 7 5 3 0 |
The team strength will be calculated as . However, if you hire programmers in better order , you will achieve a team strength of .
| New hire skill | Workrates | Motivations |
|---|---|---|
| 2 | 0 | 0 |
| 2 | 0 0 | 2 0 |
| 3 | 2 0 0 | 5 3 0 |
| 0 | 7 3 0 0 | 5 3 0 0 |
Furthermore, over the course of the upcoming days, you will receive notifications about changes in the skill level assessments of certain programmers. After day , the skill level of programmer will be updated to (which may match the previous value). This updated skill value will be used in the following days, until it potentially gets updated again.
After each day, starting from today, your goal is to determine the maximum achievable team strength by hiring all programmers, taking into account the assessed skill levels at that particular moment.
Input Format
The first line contains two integers: and .
The second line contains integers: .
Subsequently, there are lines, the -th of which contains two integers: and .
Output Format
Print lines, each containing a single integer. These integers represent the maximum potential team strength after each day, in chronological order.
4 2
2 0 2 3
2 4
4 0
10
14
12
The solution for the initial state is illustrated above. After the first day, the skill levels will be updated to and the maximum attainable team strength becomes , and after the second day, they will be further adjusted to .
Constraints
- for each .
- for each .
- for each .
Subtasks
- (11 points) ;
- (19 points)
- (15 points)
- (6 points) The skill levels never exceed .
- (9 points) The skill levels never exceed .
- (12 points) for each .
- (10 points) Each update will change the skill level by at most .
- (18 points) No additional constraints.