CF730G.Car Repair Shop

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.

Polycarp is good at marketing, so he has already collected nn requests from clients. The requests are numbered from 11 to nn in order they came.

The ii -th request is characterized by two values: sis_{i} — the day when a client wants to start the repair of his car, did_{i} — duration (in days) to repair the car. The days are enumerated from 1, the first day is tomorrow, the second day is the day after tomorrow and so on.

Polycarp is making schedule by processing requests in the order from the first to the nn -th request. He schedules the ii -th request as follows:

  • If the car repair shop is idle for did_{i} days starting from sis_{i} ( si,si+1,...,si+di1s_{i},s_{i}+1,...,s_{i}+d_{i}-1 ), then these days are used to repair a car of the ii -th client.
  • Otherwise, Polycarp finds the first day xx (from 1 and further) that there are did_{i} subsequent days when no repair is scheduled starting from xx . In other words he chooses the smallest positive xx that all days x,x+1,...,x+di1x,x+1,...,x+d_{i}-1 are not scheduled for repair of any car. So, the car of the ii -th client will be repaired in the range [x,x+di1][x,x+d_{i}-1] . It is possible that the day xx when repair is scheduled to start will be less than sis_{i} .

Given nn requests, you are asked to help Polycarp schedule all of them according to the rules above.

输入格式

The first line contains integer nn ( 1<=n<=2001<=n<=200 ) — the number of requests from clients.

The following nn lines contain requests, one request per line. The ii -th request is given as the pair of integers si,dis_{i},d_{i} ( 1<=si<=1091<=s_{i}<=10^{9} , 1<=di<=51061<=d_{i}<=5·10^{6} ), where sis_{i} is the preferred time to start repairing the ii -th car, did_{i} is the number of days to repair the ii -th car.

The requests should be processed in the order they are given in the input.

输出格式

Print nn lines. The ii -th line should contain two integers — the start day to repair the ii -th car and the finish day to repair the ii -th car.

输入输出样例

  • 输入#1

    3
    9 2
    7 3
    2 4
    

    输出#1

    9 10
    1 3
    4 7
    
  • 输入#2

    4
    1000000000 1000000
    1000000000 1000000
    100000000 1000000
    1000000000 1000000
    

    输出#2

    1000000000 1000999999
    1 1000000
    100000000 100999999
    1000001 2000000
    
首页