CF1106B.Lunar New Year and Food Ordering
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Lunar New Year is approaching, and Bob is planning to go for a famous restaurant — "Alice's".
The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always ci. Initially, the restaurant has enough ingredients for serving exactly ai dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order dj dishes of the tj-th kind of food. The (i+1)-st customer will only come after the i-th customer is completely served.
Suppose there are ri dishes of the i-th kind remaining (initially ri=ai). When a customer orders 1 dish of the i-th kind, the following principles will be processed.
- If ri>0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is ci. Meanwhile, ri will be reduced by 1.
- Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
- If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.
If the customer doesn't leave after the dj dishes are served, the cost for the customer will be the sum of the cost for these dj dishes.
Please determine the total cost for each of the m customers.
农历新年即将来临,鲍勃计划前往一家著名的餐厅——“爱丽丝餐厅”。
“爱丽丝餐厅”提供 n 种食物。第 i 种食物的单价恒为 ci。初始时,餐厅拥有恰好足够制作 ai 份第 i 种食物的食材。在除夕夜,将有 m 位顾客依次光临爱丽丝餐厅,其中第 j 位顾客将点 dj 份第 tj 种食物。第 (i+1) 位顾客仅在第 i 位顾客被完全服务完毕后才到来。
假设当前第 i 种食物还剩余 ri 份(初始时 ri=ai)。当一位顾客点 1 份第 i 种食物时,将按以下规则处理:
- 若 ri>0,则该顾客将被恰好供应 1 份第 i 种食物,费用为 ci;同时 ri 减少 1。
- 否则,若尚有其他种类的食物仍有库存,则该顾客将被供应 1 份当前最便宜的、仍有库存的食物;若存在多个价格相同的最便宜种类,则选择其中下标最小的那种。所供应食物的费用即为该种食物的单价,且对应种类的剩余份数 rk 减少 1。
- 若所有种类的食物均已售罄,则该顾客将愤怒离开。因此,无论此前已供应多少份食物,该顾客的总费用为 0。
若该顾客在成功获得全部 dj 份食物后未离开,则其费用即为这 dj 份食物费用的总和。
请计算每位顾客(共 m 位)的总费用。
输入格式
The first line contains two integers n and m (1≤n,m≤105), representing the number of different kinds of food and the number of customers, respectively.
The second line contains n positive integers a1,a2,…,an (1≤ai≤107), where ai denotes the initial remain of the i-th kind of dishes.
The third line contains n positive integers c1,c2,…,cn (1≤ci≤106), where ci denotes the cost of one dish of the i-th kind.
The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers tj and dj (1≤tj≤n, 1≤dj≤107), representing the kind of food and the number of dishes the j-th customer orders, respectively.
第一行包含两个整数 n 和 m(1≤n,m≤105),分别表示食物种类数和顾客数。
第二行包含 n 个正整数 a1,a2,…,an(1≤ai≤107),其中 ai 表示第 i 种食物的初始剩余数量。
第三行包含 n 个正整数 c1,c2,…,cn(1≤ci≤106),其中 ci 表示第 i 种食物每份的价格。
接下来的 m 行依次描述 m 位顾客的订单。第 j 行包含两个正整数 tj 和 dj(1≤tj≤n,1≤dj≤107),分别表示第 j 位顾客所点食物的种类编号及其订购份数。
输出格式
Print m lines. In the j-th line print the cost for the j-th customer.
输出 m 行。在第 j 行输出第 j 位顾客的花费。
输入输出样例
输入#1
8 5 8 6 2 1 4 5 7 5 6 3 3 2 6 2 3 2 2 8 1 4 4 7 3 4 6 10
输出#1
22 24 14 10 39
输入#2
6 6 6 6 6 6 6 6 6 66 666 6666 66666 666666 1 6 2 6 3 6 4 6 5 6 6 66
输出#2
36 396 3996 39996 399996 0
输入#3
6 6 6 6 6 6 6 6 6 66 666 6666 66666 666666 1 6 2 13 3 6 4 11 5 6 6 6
输出#3
36 11058 99996 4333326 0 0
说明/提示
In the first sample, 5 customers will be served as follows.
- Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6⋅3+1⋅2+1⋅2=22. The remain of the 8 kinds of food will be 8,0,2,0,4,4,7,5.
- Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4⋅6=24. The remain will be 4,0,2,0,4,4,7,5.
- Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4⋅2+3⋅2=14. The remain will be 4,0,2,0,4,0,7,2.
- Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2⋅3+2⋅2=10. The remain will be 4,0,0,0,4,0,7,0.
- Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7⋅3+3⋅6=39. The remain will be 1,0,0,0,4,0,0,0.
In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66⋅6=396.
In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66⋅6+666⋅6+6666⋅1=11058.
在第一个样例中,将为 5 位顾客提供服务,具体如下:
- 顾客 1 将获得 6 份第 2 种食物、1 份第 4 种食物和 1 份第 6 种食物。费用为 6⋅3+1⋅2+1⋅2=22。剩余的 8 种食物数量为 8,0,2,0,4,4,7,5。
- 顾客 2 将获得 4 份第 1 种食物。费用为 4⋅6=24。剩余食物数量为 4,0,2,0,4,4,7,5。
- 顾客 3 将获得 4 份第 6 种食物和 3 份第 8 种食物。费用为 4⋅2+3⋅2=14。剩余食物数量为 4,0,2,0,4,0,7,2。
- 顾客 4 将获得 2 份第 3 种食物和 2 份第 8 种食物。费用为 2⋅3+2⋅2=10。剩余食物数量为 4,0,0,0,4,0,7,0。
- 顾客 5 将获得 7 份第 7 种食物和 3 份第 1 种食物。费用为 7⋅3+3⋅6=39。剩余食物数量为 1,0,0,0,4,0,0,0。
在第二个样例中,除最后一位顾客外,其余每位顾客均按其订单提供食物;而最后一位顾客因不满而愤怒离店,未支付任何费用。例如,第二位顾客获得 6 份第 2 种食物,因此费用为 66⋅6=396。
在第三个样例中,部分顾客可能无法完全获得其所点的食物。例如,第二位顾客获得 6 份第 2 种食物、6 份第 3 种食物和 1 份第 4 种食物,因此费用为 66⋅6+666⋅6+6666⋅1=11058。
输入解题思路,AI测评打分。不知道怎么写?