CF644B.Processing Queries

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In this problem you have to simulate the workflow of one-thread server. There are nn queries to process, the ii -th will be received at moment tit_{i} and needs to be processed for did_{i} units of time. All tit_{i} are guaranteed to be distinct.

When a query appears server may react in three possible ways:

  1. If server is free and query queue is empty, then server immediately starts to process this query.
  2. If server is busy and there are less than bb queries in the queue, then new query is added to the end of the queue.
  3. If server is busy and there are already bb queries pending in the queue, then new query is just rejected and will never be processed.

As soon as server finished to process some query, it picks new one from the queue (if it's not empty, of course). If a new query comes at some moment xx , and the server finishes to process another query at exactly the same moment, we consider that first query is picked from the queue and only then new query appears.

For each query find the moment when the server will finish to process it or print -1 if this query will be rejected.

输入格式

The first line of the input contains two integers nn and bb ( 1<=n,b<=2000001<=n,b<=200000 ) — the number of queries and the maximum possible size of the query queue.

Then follow nn lines with queries descriptions (in chronological order). Each description consists of two integers tit_{i} and did_{i} ( 1<=ti,di<=1091<=t_{i},d_{i}<=10^{9} ), where tit_{i} is the moment of time when the ii -th query appears and did_{i} is the time server needs to process it. It is guaranteed that t_{i-1}<t_{i} for all i>1 .

输出格式

Print the sequence of nn integers e1,e2,...,ene_{1},e_{2},...,e_{n} , where eie_{i} is the moment the server will finish to process the ii -th query (queries are numbered in the order they appear in the input) or 1-1 if the corresponding query will be rejected.

输入输出样例

  • 输入#1

    5 1
    2 9
    4 8
    10 9
    15 2
    19 1
    

    输出#1

    11 19 -1 21 22 
    
  • 输入#2

    4 1
    2 8
    4 8
    10 9
    15 2
    

    输出#2

    10 18 27 -1 
    

说明/提示

Consider the first sample.

  1. The server will start to process first query at the moment 22 and will finish to process it at the moment 1111 .
  2. At the moment 44 second query appears and proceeds to the queue.
  3. At the moment 1010 third query appears. However, the server is still busy with query 11 , b=1b=1 and there is already query 22 pending in the queue, so third query is just rejected.
  4. At the moment 1111 server will finish to process first query and will take the second query from the queue.
  5. At the moment 1515 fourth query appears. As the server is currently busy it proceeds to the queue.
  6. At the moment 1919 two events occur simultaneously: server finishes to proceed the second query and the fifth query appears. As was said in the statement above, first server will finish to process the second query, then it will pick the fourth query from the queue and only then will the fifth query appear. As the queue is empty fifth query is proceed there.
  7. Server finishes to process query number 44 at the moment 2121 . Query number 55 is picked from the queue.
  8. Server finishes to process query number 55 at the moment 2222 .
首页