CF581E.Kojiro and Furrari

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Motorist Kojiro spent 1010 years saving up for his favorite car brand, Furrari. Finally Kojiro's dream came true! Kojiro now wants to get to his girlfriend Johanna to show off his car to her.

Kojiro wants to get to his girlfriend, so he will go to her along a coordinate line. For simplicity, we can assume that Kojiro is at the point ff of a coordinate line, and Johanna is at point ee . Some points of the coordinate line have gas stations. Every gas station fills with only one type of fuel: Regular-92, Premium-95 or Super-98. Thus, each gas station is characterized by a pair of integers tit_{i} and xix_{i} — the number of the gas type and its position.

One liter of fuel is enough to drive for exactly 11 km (this value does not depend on the type of fuel). Fuels of three types differ only in quality, according to the research, that affects the lifetime of the vehicle motor. A Furrari tank holds exactly ss liters of fuel (regardless of the type of fuel). At the moment of departure from point ff Kojiro's tank is completely filled with fuel Super-98. At each gas station Kojiro can fill the tank with any amount of fuel, but of course, at no point in time, the amount of fuel in the tank can be more than ss liters. Note that the tank can simultaneously have different types of fuel. The car can moves both left and right.

To extend the lifetime of the engine Kojiro seeks primarily to minimize the amount of fuel of type Regular-92. If there are several strategies to go from ff to ee , using the minimum amount of fuel of type Regular-92, it is necessary to travel so as to minimize the amount of used fuel of type Premium-95.

Write a program that can for the mm possible positions of the start fif_{i} minimize firstly, the amount of used fuel of type Regular-92 and secondly, the amount of used fuel of type Premium-95.

输入格式

The first line of the input contains four positive integers e,s,n,me,s,n,m ( 1<=e,s<=109,1<=n,m<=21051<=e,s<=10^{9},1<=n,m<=2·10^{5} ) — the coordinate of the point where Johanna is, the capacity of a Furrari tank, the number of gas stations and the number of starting points.

Next nn lines contain two integers each ti,xit_{i},x_{i} ( 1<=ti<=3,109<=xi<=1091<=t_{i}<=3,-10^{9}<=x_{i}<=10^{9} ), representing the type of the ii -th gas station ( 11 represents Regular-92, 22 — Premium-95 and 33 — Super-98) and the position on a coordinate line of the ii -th gas station. Gas stations don't necessarily follow in order from left to right.

The last line contains mm integers fif_{i} ( -10^{9}<=f_{i}<e ). Start positions don't necessarily follow in order from left to right.

No point of the coordinate line contains more than one gas station. It is possible that some of points fif_{i} or point ee coincide with a gas station.

输出格式

Print exactly mm lines. The ii -th of them should contain two integers — the minimum amount of gas of type Regular-92 and type Premium-95, if Kojiro starts at point fif_{i} . First you need to minimize the first value. If there are multiple ways to do it, you need to also minimize the second value.

If there is no way to get to Johanna from point fif_{i} , the ii -th line should look like that "-1 -1" (two numbers minus one without the quotes).

输入输出样例

  • 输入#1

    8 4 1 1
    2 4
    0
    

    输出#1

    0 4
    
  • 输入#2

    9 3 2 3
    2 3
    1 6
    -1 0 1
    

    输出#2

    -1 -1
    3 3
    3 2
    
  • 输入#3

    20 9 2 4
    1 5
    2 10
    -1 0 1 2
    

    输出#3

    -1 -1
    -1 -1
    -1 -1
    -1 -1
    
首页