Team Building
시간 제한1초메모리 제한1024 MB
N명의 프로그래머를 최적의 순서로 고용해 workrate 합을 최대화하는데, 각 직원의 workrate는 자신의 motivation만큼 증가하며, 스킬 값이 Q번 갱신될 때마다 답을 구한다.
문제
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:
The team strength will be calculated as . However, if you hire programmers in better order , you will achieve a team strength of .
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.
입력
The first line contains two integers: and .
The second line contains integers: , , , .
Subsequently, there are lines, the -th of which contains two integers: and .
출력
Print lines, each containing a single integer. These integers represent the maximum potential team strength after each day, in chronological order.
제한
- for each .
- for each .
- for each .