#P8755. [蓝桥杯 2021 省 AB2] 负载均衡
[蓝桥杯 2021 省 AB2] 负载均衡
Problem Description
There are computers. The computing capacity of the -th computer is .
A series of tasks are assigned to computers. The -th task is assigned at time , to the computer with index , with duration , and computing power consumption . If the task is assigned successfully, it starts running immediately. During its execution, it continuously occupies computing capacity of computer for seconds.
For each task assignment, if the remaining computing capacity of the computer is not enough, output and cancel this assignment. Otherwise, output the remaining computing capacity of this computer after assigning this task.
Input Format
The first line contains two integers , representing the number of computers and the number of tasks to be assigned.
The second line contains integers , representing the computing capacity of each computer.
The next lines each contain integers , with the meanings described above. The testdata guarantees that is strictly increasing, i.e., .
Output Format
Output lines. Each line contains one number, corresponding to the result of each task assignment.
2 6
5 5
1 1 5 3
2 2 2 6
3 1 2 3
4 1 6 1
5 1 3 3
6 1 3 4
2
-1
-1
1
-1
0
Hint
[Sample Explanation]
At time , task is assigned to computer , with duration . This task will end at time , and it occupies computing capacity of computer .
At time , task does not have enough required computing capacity, so the assignment fails.
At time , computer is still running task , and its remaining computing capacity is less than , so it fails.
At time , computer is still running task , but its remaining computing capacity is enough. After assignment, the remaining computing capacity is .
At time , computer is still running tasks and , and its remaining computing capacity is less than , so it fails.
At time , computer is still running task . Its remaining computing capacity is enough, and it is used up exactly.
[Constraints and Conventions for Test Cases]
For of the test cases, .
For of the test cases, .
For all test cases, $1 \leq n, m \leq 2\times 10^5, 1 \leq a_{i}, c_{i}, d_{i}, v_{i} \leq 10^{9}, 1 \leq b_{i} \leq n$.
Lanqiao Cup 2021, Round 2, Provincial Contest, Group A Problem H (Group B Problem I).
Translated by ChatGPT 5