CF1106B.Lunar New Year and Food Ordering

普及/提高-

通过率:0%

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 nn kinds of food. The cost for the ii -th kind is always cic_i . Initially, the restaurant has enough ingredients for serving exactly aia_i dishes of the ii -th kind. In the New Year's Eve, mm customers will visit Alice's one after another and the jj -th customer will order djd_j dishes of the tjt_j -th kind of food. The (i+1)(i + 1) -st customer will only come after the ii -th customer is completely served.

Suppose there are rir_i dishes of the ii -th kind remaining (initially ri=air_i = a_i ). When a customer orders 11 dish of the ii -th kind, the following principles will be processed.

  1. If ri>0r_i > 0 , the customer will be served exactly 11 dish of the ii -th kind. The cost for the dish is cic_i . Meanwhile, rir_i will be reduced by 11 .
  2. Otherwise, the customer will be served 11 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 11 .
  3. 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 00 .

If the customer doesn't leave after the djd_j dishes are served, the cost for the customer will be the sum of the cost for these djd_j dishes.

Please determine the total cost for each of the mm customers.

输入格式

The first line contains two integers nn and mm ( 1n,m1051 \leq n, m \leq 10^5 ), representing the number of different kinds of food and the number of customers, respectively.

The second line contains nn positive integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai1071 \leq a_i \leq 10^7 ), where aia_i denotes the initial remain of the ii -th kind of dishes.

The third line contains nn positive integers c1,c2,,cnc_1, c_2, \ldots, c_n ( 1ci1061 \leq c_i \leq 10^6 ), where cic_i denotes the cost of one dish of the ii -th kind.

The following mm lines describe the orders of the mm customers respectively. The jj -th line contains two positive integers tjt_j and djd_j ( 1tjn1 \leq t_j \leq n , 1dj1071 \leq d_j \leq 10^7 ), representing the kind of food and the number of dishes the jj -th customer orders, respectively.

输出格式

Print mm lines. In the jj -th line print the cost for the jj -th customer.

输入输出样例

  • 输入#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, 55 customers will be served as follows.

  1. Customer 11 will be served 66 dishes of the 22 -nd kind, 11 dish of the 44 -th kind, and 11 dish of the 66 -th kind. The cost is 63+12+12=226 \cdot 3 + 1 \cdot 2 + 1 \cdot 2 = 22 . The remain of the 88 kinds of food will be {8,0,2,0,4,4,7,5}\{8, 0, 2, 0, 4, 4, 7, 5\} .
  2. Customer 22 will be served 44 dishes of the 11 -st kind. The cost is 46=244 \cdot 6 = 24 . The remain will be {4,0,2,0,4,4,7,5}\{4, 0, 2, 0, 4, 4, 7, 5\} .
  3. Customer 33 will be served 44 dishes of the 66 -th kind, 33 dishes of the 88 -th kind. The cost is 42+32=144 \cdot 2 + 3 \cdot 2 = 14 . The remain will be {4,0,2,0,4,0,7,2}\{4, 0, 2, 0, 4, 0, 7, 2\} .
  4. Customer 44 will be served 22 dishes of the 33 -rd kind, 22 dishes of the 88 -th kind. The cost is 23+22=102 \cdot 3 + 2 \cdot 2 = 10 . The remain will be {4,0,0,0,4,0,7,0}\{4, 0, 0, 0, 4, 0, 7, 0\} .
  5. Customer 55 will be served 77 dishes of the 77 -th kind, 33 dishes of the 11 -st kind. The cost is 73+36=397 \cdot 3 + 3 \cdot 6 = 39 . The remain will be {1,0,0,0,4,0,0,0}\{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 66 dishes of the second kind, so the cost is 666=39666 \cdot 6 = 396 .

In the third sample, some customers may not be served what they order. For example, the second customer is served 66 dishes of the second kind, 66 of the third and 11 of the fourth, so the cost is 666+6666+66661=1105866 \cdot 6 + 666 \cdot 6 + 6666 \cdot 1 = 11058 .

首页