#810. T-shirts
T-shirts
T-Shirts
题面翻译
有 种 T 恤,每种有价格 和品质 。
有 个人要买 T 恤,第 个人有 元,每人每次都会买一件能买得起的 最大的 T 恤。一个人只能买一种 T 恤一件,所有人之间都是独立的。
问最后每个人买了多少件 T 恤?如果有多个 最大的 T 恤,会从价格低的开始买。
translated by Rainy_chen。
题目描述
The big consignment of t-shirts goes on sale in the shop before the beginning of the spring. In all types of t-shirts go on sale. The t-shirt of the -th type has two integer parameters — and , where — is the price of the -th type t-shirt, — is the quality of the -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, customers will come to the shop within the next month, the -th customer will get ready to spend up to 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 ( ) — the number of t-shirt types.
Each of the following lines contains two integers and ( ) — the price and the quality of the -th type t-shirt.
The next line contains the positive integer ( ) — the number of the customers.
The next line contains positive integers ( ), where the -th number is equal to the sum, which the -th customer gets ready to spend on t-shirts.
输出格式
The first line of the input data should contain the sequence of integers, where the -th number should be equal to the number of t-shirts, which the -th customer will buy.
样例 #1
样例输入 #1
3
7 5
3 5
4 3
2
13 14
样例输出 #1
2 3
样例 #2
样例输入 #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.