题号:NC54450
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
Mayor Adam East wants to improve the public transport network of Harshel city by introducing the network of stations with unicycles. Any person who owns a special card can come to a station and request a unicycle to ride or drop one.
The procedure of requesting a unicycle is simple. The person enters a queue. If there is a unicycle available, then the first person from the queue takes it immediately. Otherwise, people in the queue wait until someone drops a unicycle at the station.
Let the wait time be the time that person spends between the request (entrance to the queue) and obtaining a unicycle. If the person does not receive a unicycle at all, then the wait time is infinity. The total wait time is the sum of wait times for each person.
Adam already knows the schedule of all the people for every day. He knows at what times people request and drop unicycles at the Central Station that can hold any number of unicycles at the same time. The only thing he does not know is how many unicycles should be placed there at the start of each day. He asks you several questions to calculate the total wait time given the starting number of unicycles.
输入描述:
The first line contains n and q (1 ≤ n, q ≤ 105), where n is the total number of unicycle requests and unicycle drops at the Central Station, and q is the number of questions Adam asks you. The next n lines describe operations at the Central Station. Each line contains one description of operation:
• “+ t k” when k unicycles are dropped at time t;
• “- t k” when k people request unicycles at time t.
For each of the described operations 1 ≤ t ≤ 109 and 1 ≤ k ≤ 104. The last line of the input contains q different integers bi (0 ≤ bi ≤ 109) — the number of unicycles at the start of the day.
The operations are given in the strongly increasing order of time.
输出描述:
The output shall consist of q lines. The i-th line shall display the total wait time for the case of bi unicycles at the start of the day. If the total wait time is infinite, then the corresponding line shall display the word “INFINITY”.
示例1
输入
复制
5 4
- 1 1
- 2 2
+ 4 1
- 6 1
+ 7 2
0 3 1 2
备注:
Author: Vitaliy Aksenov