CF702F.T-Shirts

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

The big consignment of t-shirts goes on sale in the shop before the beginning of the spring. In all nn types of t-shirts go on sale. The t-shirt of the ii -th type has two integer parameters — cic_{i} and qiq_{i} , where cic_{i} — is the price of the ii -th type t-shirt, qiq_{i} — is the quality of the ii -th type t-shirt. It should be assumed that the unlimited number of t-shirts of each type goes on sale in the shop, but in general the quality is not concerned with the price.

As predicted, kk customers will come to the shop within the next month, the jj -th customer will get ready to spend up to bjb_{j} on buying t-shirts.

All customers have the same strategy. First of all, the customer wants to buy the maximum possible number of the highest quality t-shirts, then to buy the maximum possible number of the highest quality t-shirts from residuary t-shirts and so on. At the same time among several same quality t-shirts the customer will buy one that is cheaper. The customers don't like the same t-shirts, so each customer will not buy more than one t-shirt of one type.

Determine the number of t-shirts which each customer will buy, if they use the described strategy. All customers act independently from each other, and the purchase of one does not affect the purchase of another.

输入格式

The first line contains the positive integer nn ( 1<=n<=21051<=n<=2·10^{5} ) — the number of t-shirt types.

Each of the following nn lines contains two integers cic_{i} and qiq_{i} ( 1<=ci,qi<=1091<=c_{i},q_{i}<=10^{9} ) — the price and the quality of the ii -th type t-shirt.

The next line contains the positive integer kk ( 1<=k<=21051<=k<=2·10^{5} ) — the number of the customers.

The next line contains kk positive integers b1,b2,...,bkb_{1},b_{2},...,b_{k} ( 1<=bj<=1091<=b_{j}<=10^{9} ), where the jj -th number is equal to the sum, which the jj -th customer gets ready to spend on t-shirts.

输出格式

The first line of the input data should contain the sequence of kk integers, where the ii -th number should be equal to the number of t-shirts, which the ii -th customer will buy.

输入输出样例

  • 输入#1

    3
    7 5
    3 5
    4 3
    2
    13 14
    

    输出#1

    2 3 
    
  • 输入#2

    2
    100 500
    50 499
    4
    50 200 150 100
    

    输出#2

    1 2 2 1 
    

说明/提示

In the first example the first customer will buy the t-shirt of the second type, then the t-shirt of the first type. He will spend 10 and will not be able to buy the t-shirt of the third type because it costs 4, and the customer will owe only 3. The second customer will buy all three t-shirts (at first, the t-shirt of the second type, then the t-shirt of the first type, and then the t-shirt of the third type). He will spend all money on it.

首页