CF883L.Berland.Taxi

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Berland.Taxi is a new taxi company with kk cars which started operating in the capital of Berland just recently. The capital has nn houses on a straight line numbered from 11 (leftmost) to nn (rightmost), and the distance between any two neighboring houses is the same.

You have to help the company schedule all the taxi rides which come throughout the day according to the following rules:

  • All cars are available for picking up passengers. Initially the jj -th car is located next to the house with the number xjx_{j} at time 00 .
  • All cars have the same speed. It takes exactly 11 minute for any car to travel between neighboring houses ii and i+1i+1 .
  • The ii -th request for taxi ride comes at the time tit_{i} , asking for a passenger to be picked up at the house aia_{i} and dropped off at the house bib_{i} . All requests for taxi rides are given in the increasing order of tit_{i} . All tit_{i} are distinct.

When a request for taxi ride is received at time tit_{i} , Berland.Taxi operator assigns a car to it as follows:

  • Out of cars which are currently available, operator assigns the car which is the closest to the pick up spot aia_{i} . Needless to say, if a car is already on a ride with a passenger, it won't be available for any rides until that passenger is dropped off at the corresponding destination.
  • If there are several such cars, operator will pick one of them which has been waiting the most since it became available.
  • If there are several such cars, operator will pick one of them which has the lowest number.

After a car gets assigned to the taxi ride request:

  • The driver immediately starts driving from current position to the house aia_{i} .
  • Once the car reaches house aia_{i} , the passenger is immediately picked up and the driver starts driving to house bib_{i} .
  • Once house bib_{i} is reached, the passenger gets dropped off and the car becomes available for new rides staying next to the house bib_{i} .
  • It is allowed for multiple cars to be located next to the same house at the same point in time, while waiting for ride requests or just passing by.

If there are no available cars at time tit_{i} when a request for taxi ride comes, then:

  • The ii -th passenger will have to wait for a car to become available.
  • When a car becomes available, operator will immediately assign it to this taxi ride request.
  • If multiple cars become available at once while the passenger is waiting, operator will pick a car out of them according to the rules described above.

Operator processes taxi ride requests one by one. So if multiple passengers are waiting for the cars to become available, operator will not move on to processing the (i+1)(i+1) -th ride request until the car gets assigned to the ii -th ride request.

Your task is to write a program that will process the given list of mm taxi ride requests. For each request you have to find out which car will get assigned to it, and how long the passenger will have to wait for a car to arrive. Note, if there is already car located at the house aia_{i} , then the corresponding wait time will be 00 .

输入格式

The first line of input contains integers nn , kk and mm ( 2<=n<=21052<=n<=2·10^{5} , 1<=k,m<=21051<=k,m<=2·10^{5} ) — number of houses, number of cars, and number of taxi ride requests. The second line contains integers x1,x2,...,xkx_{1},x_{2},...,x_{k} ( 1<=xi<=n1<=x_{i}<=n ) — initial positions of cars. xix_{i} is a house number at which the ii -th car is located initially. It's allowed for more than one car to be located next to the same house.

The following mm lines contain information about ride requests. Each ride request is represented by integers tjt_{j} , aja_{j} and bjb_{j} ( 1<=tj<=10121<=t_{j}<=10^{12} , 1<=aj,bj<=n1<=a_{j},b_{j}<=n , ajbja_{j}≠b_{j} ), where tjt_{j} is time in minutes when a request is made, aja_{j} is a house where passenger needs to be picked up, and bjb_{j} is a house where passenger needs to be dropped off. All taxi ride requests are given in the increasing order of tjt_{j} . All tjt_{j} are distinct.

输出格式

Print mm lines: the jj -th line should contain two integer numbers, the answer for the jj -th ride request — car number assigned by the operator and passenger wait time.

输入输出样例

  • 输入#1

    10 1 2
    3
    5 2 8
    9 10 3
    

    输出#1

    1 1
    1 5
    
  • 输入#2

    5 2 1
    1 5
    10 3 5
    

    输出#2

    1 2
    
  • 输入#3

    5 2 2
    1 5
    10 3 5
    20 4 1
    

    输出#3

    1 2
    2 1
    

说明/提示

In the first sample test, a request comes in at time 55 and the car needs to get from house 33 to house 22 to pick up the passenger. Therefore wait time will be 11 and the ride will be completed at time 5+1+6=125+1+6=12 . The second request comes in at time 99 , so the passenger will have to wait for the car to become available at time 1212 , and then the car needs another 22 minutes to get from house 88 to house 1010 . So the total wait time is 3+2=53+2=5 .

In the second sample test, cars 11 and 22 are located at the same distance from the first passenger and have the same "wait time since it became available". Car 11 wins a tiebreaker according to the rules because it has the lowest number. It will come to house 33 at time 33 , so the wait time will be 22 .

首页