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 $c_i$. Initially, the restaurant has enough ingredients for serving exactly $a_i$ 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 $d_j$ dishes of the $t_j$-th kind of food. The $(i + 1)$-st customer will only come after the $i$-th customer is completely served.

Suppose there are $r_i$ dishes of the $i$-th kind remaining (initially $r_i = a_i$). When a customer orders $1$ dish of the $i$-th kind, the following principles will be processed. If $r_i > 0$, the customer will be served exactly $1$ dish of the $i$-th kind. The cost for the dish is $c_i$. Meanwhile, $r_i$ 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 $d_j$ dishes are served, the cost for the customer will be the sum of the cost for these $d_j$ dishes.

Please determine the total cost for each of the $m$ customers.


-----Input-----

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

The second line contains $n$ positive integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^7$), where $a_i$ denotes the initial remain of the $i$-th kind of dishes.

The third line contains $n$ positive integers $c_1, c_2, \ldots, c_n$ ($1 \leq c_i \leq 10^6$), where $c_i$ 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 $t_j$ and $d_j$ ($1 \leq t_j \leq n$, $1 \leq d_j \leq 10^7$), representing the kind of food and the number of dishes the $j$-th customer orders, respectively.


-----Output-----

Print $m$ lines. In the $j$-th line print the cost for the $j$-th customer.


-----Examples-----
Input
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

Output
22
24
14
10
39

Input
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

Output
36
396
3996
39996
399996
0

Input
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

Output
36
11058
99996
4333326
0
0



-----Note-----

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 \cdot 3 + 1 \cdot 2 + 1 \cdot 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 \cdot 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 \cdot 2 + 3 \cdot 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 \cdot 3 + 2 \cdot 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 \cdot 3 + 3 \cdot 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 \cdot 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 \cdot 6 + 666 \cdot 6 + 6666 \cdot 1 = 11058$.

Difficulty: interview

Starter code:

Solutions:
n, m = map(int, input().split())
a = list(map(int, input().split()))
c = list(map(int, input().split()))
mc = sorted(((y, x) for x, y in enumerate(c)), reverse=True)
for _ in range(m):
    t, d = map(int, input().split())
    t -= 1
    if a[t] >= d:
        print(c[t] * d)
        a[t] -= d
    else:
        x = a[t] * c[t]
        d -= a[t]
        a[t] = 0
        while d:
            if not mc:
                print(0)
                break
            cost, index = mc[-1]
            if a[index] >= d:
                x += cost * d
                a[index] -= d
                d = 0
            else:
                x += cost * a[index]
                d -= a[index]
                a[index] = 0
            if a[index] == 0:
                mc.pop()
        else:
            print(x)

def main():
    n, m = list(map(int, input().split()))
    a = list(map(int, input().split()))
    c = list(map(int, input().split()))
    b = [(c[i], i) for i in range(n)]
    b.sort()
    b = [b[i][1] for i in range(n)]
    bi = 0
    for i in range(m):
        t, d = list(map(int, input().split()))
        t -= 1
        s = 0
        if a[t] >= d:
            a[t] -= d
            print(d * c[t])
        else:
            s += a[t] * c[t]
            d -= a[t]
            a[t] = 0
            while bi < n:
                if a[b[bi]] >= d:
                    s += d * c[b[bi]]
                    a[b[bi]] -= d
                    d = 0
                    break
                s += a[b[bi]] * c[b[bi]]
                d -= a[b[bi]]
                a[b[bi]] = 0
                bi += 1
            if d > 0:
                print(0)
            else:
                print(s)

main()


n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
c = list(map(int, input().split()))

ss = [(i, c[i]) for i in range(n)]
ss = sorted(ss, key=lambda x: (x[1], x[0]))
p = 0
ans1 = []
for _ in range(m):
    t, d = list(map(int, input().split()))
    t -=1
    ans = 0
    c1 = min(d, a[t])
    a[t] -= c1
    ans += c1*c[t]
    d -= c1
    while d > 0 and p < n:
        nt = ss[p][0]
        nc = ss[p][1]
        c2 = min(a[nt], d)
        a[nt] -= c2
        d -= c2
        ans += nc*c2
        if a[nt] == 0:
            p += 1
    if d == 0:
        print(ans)
    else:
        print(0)


import sys
n, m = map(int, input().split())
dishes = list(map(int, input().split()))
costs = list(map(int, input().split()))
cheaper = [i for i, v in sorted(enumerate(costs), key=lambda x: (x[1], x[0]), reverse=True)]

ans = []
append = ans.append

for t, d in (map(int, l.split()) for l in sys.stdin):
    t -= 1
    count = min(d, dishes[t])
    price = costs[t] * count
    dishes[t] -= count
    d -= count
    while d and cheaper:
        t = cheaper[-1]
        count = min(d, dishes[t])
        dishes[t] -= count
        if not dishes[t]:
            cheaper.pop()
        price += costs[t] * count
        d -= count

    append(0 if d else price)

print(*ans, sep="\n")

# list(map(int, input().split()))
n, m = list(map(int, input().split()))
ost = list(map(int, input().split()))
price = list(map(int, input().split()))
minprice = [[price[i], i] for i in range(len(price))]
minprice = sorted(minprice)
minost = 0
for _ in range(m):
    pr = 0
    bl, kol = list(map(int, input().split()))
    bl -= 1
    if (ost[bl] >= kol):
        pr = kol * price[bl]
        ost[bl] -= kol
    else:
        kol -= ost[bl]
        pr = ost[bl] * price[bl]
        ost[bl] = 0
        while(kol > 0):
            if (minost == n):
                pr = 0
                break
            minbl = minprice[minost][1]
            if (ost[minbl] >= kol):
                pr += kol * price[minbl]
                ost[minbl] -= kol
                kol = 0
            else:
                kol -= ost[minbl]
                pr += ost[minbl] * price[minbl]
                ost[minbl] = 0
                minost += 1
                if (minost == n):
                    pr = 0
                    break
    print(pr)

n, m = list(map(int, input().split()))

dish = list(map(int, input().split()))
cost = list(map(int, input().split()))
scost = []
for i in range(n):
    scost.append([cost[i], dish[i], i])
scost = sorted(scost)
# print(scost)

cur = 0
for i in range(m):
    x, y = list(map(int, input().split()))
    x -= 1
    # print(x, y)
    price = 0
    if dish[x] >= y:
        price += cost[x] * y
        dish[x] -= y
        y = 0
    else:
        price += cost[x] * dish[x]
        y -= dish[x]
        dish[x] = 0

        while y > 0:
            try:
                tmp = scost[cur][-1]

                # print("cur", cur, scost[cur])

                if dish[tmp] >= y:
                    price += cost[tmp] * y
                    dish[tmp] -= y
                    y = 0

                else:
                    price += cost[tmp] * dish[tmp]
                    y -= dish[tmp]
                    dish[tmp] = 0
                    cur += 1
            except IndexError:
                price = 0
                y = 0
    # print(dish)

    print(price)
    # print()


def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())

n, m = mi()
a = li()
c = li()

x = list(range(n))
x.sort(key=lambda i: (c[i], i))
cur = 0

out = []
for i in range(m):
    t, d = mi()
    p = min(d, a[t - 1])
    d -= p
    a[t - 1] -= p
    ans = c[t - 1] * p
    while d:
        while cur < n and a[x[cur]] == 0:
            cur += 1
        if cur == n:
            ans = 0
            break
        p = min(d, a[x[cur]])
        d -= p
        a[x[cur]] -= p
        ans += c[x[cur]] * p
    out.append(str(ans))

print(*out, sep='\n')


import sys
read = lambda : list(map(int, sys.stdin.readline().split()))
write = sys.stdout.write

n, m = read()
dish = [0] + list(read())
dishes = sum(dish)
cost = [0] + list(read())

remain = []
for i in range(1, n+1):
    remain.append(
        [cost[i], i]
    )
remain.sort(reverse=True)

for i in range(m):
    t, d = read()
    ans = 0

    if dishes == 0:
        write("0\n")

    elif dish[t] >= d:
        dishes -= d 
        dish[t] -= d
        write(f"{cost[t]*d}\n")
    
    elif dish[t] < d:
        ans += dish[t] * cost[t]
        dishes -= dish[t]
        d -= dish[t]
        dish[t] = 0
        #print(d, dish)

        while d > 0 and dishes > 0:
            k = remain[-1][1]
            #print(k, dish[k], cost[k])

            if dish[k] >= d:
                dish[k] -= d 
                dishes -= d   
                ans += cost[k] * d
                d = 0
            else:
                dishes -= dish[k]
                d -= dish[k]
                ans += cost[k] * dish[k]
                dish[k] = 0
                remain.pop()
        
        if d > 0 and dishes == 0:
            write("0\n")
        else:
            write(f"{ans}\n")
                






n,m=list(map(int,input().split()))#kinds of food,customers
A=[0]+list(map(int,input().split()))#initial remain of i-th foods
C=[0]+list(map(int,input().split()))#costs
O=[list(map(int,input().split())) for i in range(m)]

C2=[[C[i+1],i+1] for i in range(n)]
C2.sort()

C2NOW=0

for f,d in O:
    ANS=0
    if A[f]>=d:
        ANS+=C[f]*d
        A[f]-=d
        print(ANS)
        continue
    

    else:
        ANS+=A[f]*C[f]
        d-=A[f]
        A[f]=0
        #print(ANS,f,d,C2[C2NOW])

        while d>0:
            
            if C2NOW==n:
                ANS=0
                d=0
                break
            
            if A[C2[C2NOW][1]]==0:
                C2NOW+=1
                continue
            
            if A[C2[C2NOW][1]]>=d:
                ANS+=d*C2[C2NOW][0]
                A[C2[C2NOW][1]]-=d
                d=0

            else:
                ANS+=A[C2[C2NOW][1]]*C2[C2NOW][0]
                d-=A[C2[C2NOW][1]]
                A[C2[C2NOW][1]]=0
                C2NOW+=1

        print(ANS)
                
                


import sys
#sys.setrecursionlimit(200000)
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
c = list(map(int,input().split()))
z = list(range(n))
d = []
for i,j,k in zip(a,c,z):
        d.append([j,i,k])
d.sort(key=lambda x : -x[0])
for i in range(m):
        x,y = map(int,input().split())
        x-=1
        ans = 0
        if a[x]:
                if a[x] >= y:
                        print(c[x]*y)
                        a[x] -= y
                        continue
                else:
                        ans += a[x]*c[x]
                        y -= a[x]
                        a[x] = 0
        while d and y>0:
                q,w,e = d.pop()
                w = a[e]
                if w >= y:
                        ans += q*y
                        a[e] = w-y
                        y = 0
                        d.append([q,w-y,e])
                else:
                        ans += w*q
                        a[e] = 0
                        y-= w
        if y:
                print(0)
        else:
                print(ans)

# cook your dish here
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=list(map(int,input().split()))
cl=[]
for i in range(n):
    cl.append([c[i],i])
#print(cl)
def fun(itm):
    return itm[0]
cl.sort(key=fun)
idx=0
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    cost=0
    if(a[x]>=y):
        a[x]-=y
        cost+=c[x]*y
        y=0
    else:
        cost+=c[x]*a[x]
        y-=a[x]
        a[x]=0
        flag=0
        while(idx<n and y>0):
            if(a[cl[idx][1]]>=y):
                a[cl[idx][1]]-=y
                cost+=cl[idx][0]*y
                y=0
                flag=1
            else:
                cost+=cl[idx][0]*a[cl[idx][1]]
                y-=a[cl[idx][1]]
                a[cl[idx][1]]=0
                idx+=1
        if(flag==0):
            cost=0
    print(cost)

n, m = list(map(int, input().lstrip().split(' ')))

a = list(map(int, input().lstrip().split(' ')))
c = list(map(int, input().lstrip().split(' ')))

costs = sorted([(i, cost) for i, cost in enumerate(c)],
               key=lambda x: (x[1], x[0]))
ci = 0
# print(costs)
for _ in range(m):
    cost = 0
    t, d = list(map(int, input().lstrip().split(' ')))
    t -= 1
    if a[t] > d:
        cost = d * c[t]
        a[t] -= d
    else:
        cost = a[t] * c[t]
        d -= a[t]
        a[t] = 0
        while d > 0 and ci < n:
            ai, _cost = costs[ci]
            if a[ai] > d:
                cost += d * _cost
                a[ai] -= d
                d = 0
            else:
                cost += a[ai] * _cost
                d -= a[ai]
                a[ai] = 0
                ci += 1
        if d > 0:
            cost = 0
    # print(a)
    print(cost)


import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque

n,m = li()
a = list(li())
c = list(li())

# dictionary of idx-num
dic = {idx: ai for idx, ai in enumerate(a)}

# cheap order
cord = [idx for (_, idx) in sorted([(ci, idx) for idx,ci in enumerate(c)])]
cord = deque(cord)

for _ in range(m):
    dish, num = li()
    dish -= 1
    
    ans = 0
    
    if num <= dic[dish]:
        dic[dish] -= num
        ans = c[dish]*num
        print(ans)
        
    else:
        ans = c[dish]*dic[dish]
        num -= dic[dish]
        dic[dish] = 0
        
        while num > 0:
            if cord:
                nex = cord.popleft()
            else:
                ans = 0
                num = 0
            
            if dic[nex] > num:
                ans += c[nex] * num
                dic[nex] -= num
                cord.appendleft(nex)
                num = 0
                
            elif dic[nex] == num:
                ans += c[nex] * num
                dic[nex] = 0
                num = 0
                
            else:
                ans += c[nex] * dic[nex]
                num -= dic[nex]
                dic[nex] = 0
                
        print(ans)


num_dishes, num_customers = [int(x) for x in input().split()]

dish_amounts = [int(x) for x in input().split()]
dish_costs = [int(x) for x in input().split()]

dishes_by_price = sorted(list(range(num_dishes)), key=lambda i : dish_costs[i])
dbp_i = 0

for j in range(num_customers):
    dish, amount = [int(x) for x in input().split()]
    dish -= 1
    served = min(dish_amounts[dish], amount)
    dish_amounts[dish] -= served

    cost = served * dish_costs[dish]
    not_served = amount - served
    # print(j, dish, served)

    while not_served > 0 and dbp_i != num_dishes:
        i = dishes_by_price[dbp_i]
        served = min(dish_amounts[i], not_served)
        cost += served * dish_costs[i]
        dish_amounts[i] -= served
        not_served -= served
        # print(j, i, served)

        if dish_amounts[i] == 0:
            dbp_i += 1

    if not_served > 0:
        cost = 0

    print(cost)


n, m = map(int, input().split())
a = [int(s) for s in input().split()]
c = [int(s) for s in input().split()]
types = dict()
for i in range(n):
    types[i] = c[i]
types = sorted(types.items(), key=lambda kv: kv[1])
#print(types)
min_c = types[0]
ind = 0
for i in range(m):
    t, d = map(int, input().split())
    t -= 1
    summ = 0
    if a[t] < d:
        summ += a[t]*c[t]
        d -= a[t]
        a[t] = 0
        while a[min_c[0]] < d:
            summ += a[min_c[0]]*c[min_c[0]]
            d -= a[min_c[0]]
            a[min_c[0]] = 0
            ind += 1
            if ind >= n:
                summ = 0
                ind -= 1
                break
            else:
                min_c = types[ind]
        else:
            summ += d*c[min_c[0]]
            a[min_c[0]] -= d
    else:
        summ += d*c[t]
        a[t] -= d
    print(summ)

'''input
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
'''
import sys
from collections import defaultdict as dd
from itertools import  permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
import heapq
mod=10**9+7

def ri(flag=0):
	if flag==0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())

n,m=ri()
a=ri()
c=ri()

hee=[]

for i in range(n):
	heapq.heappush(hee,(c[i],i))

avail=a[:]

for i in range(m):
	cost=0
	t,d=ri()
	t-=1
	fm=0
	if avail[t]>=d:
		avail[t]=avail[t]-d
		cost+=(d*c[t])
	else:
		rem=d-avail[t]
		cost=avail[t]*c[t]
		avail[t]=0
		while rem>0:
			try:
				nowc,nowi=heapq.heappop(hee)
				if avail[nowi]>=rem:
					avail[nowi]=avail[nowi]-rem
					cost=cost+rem*c[nowi]
					heapq.heappush(hee,(c[nowi],nowi))
					rem=0
				else:
					cost=cost+avail[nowi]*c[nowi]
					mk=rem-avail[nowi]
					avail[nowi]=0
					rem=mk
			except:
				fm=1
				break
	if fm==0:
		print(cost)
	else:
		print(0)






import copy
import fractions
import itertools
import numbers
import string
import sys

###

def powmod(x, p, m):
	if p <= 0:
		return 1
	if p <= 1:
		return x%m
	return powmod(x*x%m, p//2, m) * (x%m)**(p%2) % m

###

def to_basex(num, x):
	while num > 0:
		yield num % x
		num //= x

def from_basex(it, x):
	ret = 0
	p = 1
	for d in it:
		ret += d*p
		p *= x
	return ret

###

def core():
	n, m = (int(x) for x in input().split())
	a = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	s = [(c[i], i) for i in range(n)]
	s.sort(reverse=True)
	
	# print(a)
	# print(s)
	for _ in range(m):
		if not s:
			print(0)
		else:
			tj, dj = (int(x) for x in input().split())
			tj -= 1
			
			if a[tj] >= dj:
				print(dj*c[tj])
				a[tj] -= dj
			else:
				bill = a[tj]*c[tj]
				dj -= a[tj]
				a[tj] = 0
				while dj > 0:
					# print("dj0, bill0: %d, %d" % (dj, bill))
					if not s:
						bill = 0
						break
					
					if a[s[-1][1]] == 0:
						_ = s.pop()
					elif a[s[-1][1]] >= dj:
						bill += dj*c[s[-1][1]]
						a[s[-1][1]] -= dj
						dj = 0
					else:
						bill += a[s[-1][1]]*c[s[-1][1]]
						dj -= a[s[-1][1]]
						a[s[-1][1]] = 0
						_ = s.pop()
					# print("dj, bill: %d, %d" % (dj, bill))
				print(bill)
		# print(a)
		# print(s)


core()





















def inpl(): return list(map(int, input().split()))
N, M = inpl()
A = inpl()
C = inpl()
Dishnum = sum(A)
ACi = [[c, i, a] for i, (a, c) in enumerate(zip(A, C), 1)]
ACi.sort()
Orig = dict()
for i, (_, j, _) in enumerate(ACi):
    Orig[j] = i
ctr = 0
for _ in range(M):
    ans = 0
    t, d = inpl()
    t = Orig[t]
    Dishnum -= d
    if Dishnum < 0:
        print(ans)
        continue
    k = min(d, ACi[t][2])
    ACi[t][2] -= k
    d -= k
    ans += k*ACi[t][0]
    while d > 0:
        k = min(d, ACi[ctr][2])
        ACi[ctr][2] -= k
        d -= k
        ans += k*ACi[ctr][0]
        if not ACi[ctr][2]:
            ctr += 1
    print(ans)

# -*- coding: utf-8 -*-
# @Time    : 2019/1/31 20:48
# @Author  : LunaFire
# @Email   : gilgemesh2012@gmail.com
# @File    : B. Lunar New Year and Food Ordering.py


def main():
    n, m = list(map(int, input().split()))
    a = list(map(int, input().split()))
    c = list(map(int, input().split()))

    price_index = []
    for i in range(n):
        price_index.append((c[i], i))
    price_index.sort()
    # print(price_index)

    ptr = 0
    for _ in range(m):
        t, d = list(map(int, input().split()))
        t -= 1
        cost = 0

        if a[t] > 0:
            served_num = min(a[t], d)
            a[t] -= served_num
            d -= served_num
            cost += served_num * c[t]

        while ptr < n and d > 0:
            _, index = price_index[ptr]
            if a[index] == 0:
                ptr += 1
            served_num = min(a[index], d)
            a[index] -= served_num
            d -= served_num
            cost += served_num * c[index]

        if d > 0:
            print(0)
        else:
            print(cost)


def __starting_point():
    main()

__starting_point()

m,n=[int(x) for x in input().split()]
r=[int(x) for x in input().split()]
cost=[int(x) for x in input().split()]
costa=[]
i=1
for item in cost:
    a=[item,i,r[i-1]]
    costa.append(a)
    i+=1
counter=0
costa.sort(reverse=True)
dic={}
i=0
for item in costa:
    dic[item[1]]=i
    i+=1
index=len(costa)-1
for item in range(n):
    counter=0
    a,b=[int(x) for x in input().split()]
    if r[a-1]>=b:
        counter+=cost[a-1]*b
        r[a-1]-=b
        costa[dic[a]][2]-=b
    else:
        i=index
        counter+=cost[a-1]*r[a-1]
        costa[dic[a]][2]=0
        b-=r[a-1]
        r[a-1]=0
        while i>=0:
            if costa[i][2]>=b:
                counter+=costa[i][0]*b
                r[costa[i][1]-1]-=b
                costa[i][2]-=b
                break
            else:
                counter+=costa[i][0]*costa[i][2]
                r[costa[i][1]-1]=0
                index-=1
                b-=costa[i][2]
                costa[i][2]=0
            i-=1
        else:
            counter=0
    print(counter)


import sys
n, m = [int(tmp) for tmp in sys.stdin.readline().split()]
a = [0] + [int(tmp) for tmp in sys.stdin.readline().split()]
c = [0] + [int(tmp) for tmp in sys.stdin.readline().split()]

co = [tmp for tmp in range(n+1)]
co.sort(key=lambda z: c[z])
cop = 1
nb = False
for i in range(m):
    t, d = [int(tmp) for tmp in sys.stdin.readline().split()]
    if nb:
        print(0)
        continue
    s = 0
    botf = min([d, a[t]])
    a[t] -= botf
    s = botf * c[t]
    brts = d - botf
    while brts != 0:
        botf = min([brts, a[co[cop]]])
        if botf == 0:
            cop += 1
            if cop == n + 1:
                nb = True
                s = 0
                break
        a[co[cop]] -= botf
        brts -= botf
        s += botf * c[co[cop]]
    print(s)


''' CODED WITH LOVE BY SATYAM KUMAR '''


from sys import stdin, stdout
import cProfile, math
from collections import Counter,deque
from bisect import bisect_left,bisect,bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
sys.setrecursionlimit(10**6) # max depth of recursion
threading.stack_size(2**27)  # new thread will get stack of such size
fac_warmup = False
printHeap = str()
memory_constrained = False
P = 10**9+7
import sys

class Operation:
    def __init__(self, name, function, function_on_equal, neutral_value=0):
        self.name = name
        self.f = function
        self.f_on_equal = function_on_equal
def add_multiple(x, count):
    return x * count
def min_multiple(x, count):
    return x
def max_multiple(x, count):
    return x
sum_operation = Operation("sum", sum, add_multiple, 0)
min_operation = Operation("min", min, min_multiple, 1e9)
max_operation = Operation("max", max, max_multiple, -1e9)
class SegmentTree:
    def __init__(self,
                 array,
                 operations=[sum_operation, min_operation, max_operation]):
        self.array = array
        if type(operations) != list:
            raise TypeError("operations must be a list")
        self.operations = {}
        for op in operations:
            self.operations[op.name] = op
        self.root = SegmentTreeNode(0, len(array) - 1, self)
    def query(self, start, end, operation_name):
        if self.operations.get(operation_name) == None:
            raise Exception("This operation is not available")
        return self.root._query(start, end, self.operations[operation_name])
    def summary(self):
        return self.root.values
    def update(self, position, value):
        self.root._update(position, value)
    def update_range(self, start, end, value):
        self.root._update_range(start, end, value)
    def __repr__(self):
        return self.root.__repr__()
class SegmentTreeNode:
    def __init__(self, start, end, segment_tree):
        self.range = (start, end)
        self.parent_tree = segment_tree
        self.range_value = None
        self.values = {}
        self.left = None
        self.right = None
        if start == end:
            self._sync()
            return
        self.left = SegmentTreeNode(start, start + (end - start) // 2,
                                    segment_tree)
        self.right = SegmentTreeNode(start + (end - start) // 2 + 1, end,
                                     segment_tree)
        self._sync()
    def _query(self, start, end, operation):
        if end < self.range[0] or start > self.range[1]:
            return None
        if start <= self.range[0] and self.range[1] <= end:
            return self.values[operation.name]
        self._push()
        left_res = self.left._query(start, end,
                                    operation) if self.left else None
        right_res = self.right._query(start, end,
                                      operation) if self.right else None
        if left_res is None:
            return right_res
        if right_res is None:
            return left_res
        return operation.f([left_res, right_res])
    def _update(self, position, value):
        if position < self.range[0] or position > self.range[1]:
            return
        if position == self.range[0] and self.range[1] == position:
            self.parent_tree.array[position] = value
            self._sync()
            return
        self._push()
        self.left._update(position, value)
        self.right._update(position, value)
        self._sync()
    def _update_range(self, start, end, value):
        if end < self.range[0] or start > self.range[1]:
            return
        if start <= self.range[0] and self.range[1] <= end:
            self.range_value = value
            self._sync()
            return
        self._push()
        self.left._update_range(start, end, value)
        self.right._update_range(start, end, value)
        self._sync()
    def _sync(self):
        if self.range[0] == self.range[1]:
            for op in self.parent_tree.operations.values():
                current_value = self.parent_tree.array[self.range[0]]
                if self.range_value is not None:
                    current_value = self.range_value
                self.values[op.name] = op.f([current_value])
        else:
            for op in self.parent_tree.operations.values():
                result = op.f(
                    [self.left.values[op.name], self.right.values[op.name]])
                if self.range_value is not None:
                    bound_length = self.range[1] - self.range[0] + 1
                    result = op.f_on_equal(self.range_value, bound_length)
                self.values[op.name] = result
    def _push(self):
        if self.range_value is None:
            return
        if self.left:
            self.left.range_value = self.range_value
            self.right.range_value = self.range_value
            self.left._sync()
            self.right._sync()
            self.range_value = None
    def __repr__(self):
        ans = "({}, {}): {}\n".format(self.range[0], self.range[1],
                                      self.values)
        if self.left:
            ans += self.left.__repr__()
        if self.right:
            ans += self.right.__repr__()
        return ans

def display(string_to_print):
    stdout.write(str(string_to_print) + "\n")

def primeFactors(n): #n**0.5 complex 
    factors = dict()
    for i in range(2,math.ceil(math.sqrt(n))+1):  
        while n % i== 0: 
            if i in factors:
                factors[i]+=1
            else: factors[i]=1
            n = n // i 
    if n>2:
        factors[n]=1
    return (factors)
    
def isprime(n):
    """Returns True if n is prime."""
    if n < 4:
        return True
    if n % 2 == 0:
        return False
    if n % 3 == 0:
        return False
    i = 5
    w = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += w
        w = 6 - w
    return True
factorial_modP = []
def warm_up_fac(MOD):
    nonlocal factorial_modP,fac_warmup
    if fac_warmup: return
    factorial_modP= [1 for _ in range(fac_warmup_size+1)]
    for i in range(2,fac_warmup_size):
        factorial_modP[i]= (factorial_modP[i-1]*i) % MOD
    fac_warmup = True

def InverseEuler(n,MOD):
    return pow(n,MOD-2,MOD)

def nCr(n, r, MOD):
    nonlocal fac_warmup,factorial_modP
    if not fac_warmup:
        warm_up_fac(MOD)
        fac_warmup = True
    return (factorial_modP[n]*((pow(factorial_modP[r], MOD-2, MOD) * pow(factorial_modP[n-r], MOD-2, MOD)) % MOD)) % MOD

def test_print(*args):
    if testingMode:
        print(args)

def display_list(list1, sep=" "):
    stdout.write(sep.join(map(str, list1)) + "\n")

def get_int():
    return int(stdin.readline().strip())

def get_tuple():
    return map(int, stdin.readline().split())

def get_list():
    return list(map(int, stdin.readline().split()))

memory = dict()
def clear_cache():
    nonlocal memory
    memory = dict()
def cached_fn(fn, *args):
    nonlocal memory
    if args in memory:
        return memory[args]
    else:
        result = fn(*args)
        memory[args] = result
        return result


# -------------------------------------------------------------- MAIN PROGRAM
TestCases = False
testingMode = False
fac_warmup_size = 10**5+100
optimiseForReccursion = True #Can not be used clubbed with TestCases


def main():
    n,m = get_tuple()
    remaining = get_list()
    costs = get_list()
    ki = [(ele,i) for i,ele in enumerate(costs)]
    ki.sort()
    ind = 0
    res = []
    #print(ki,costs,remaining)
    for _ in range(m):
        t,d = get_tuple() #Kind of food and no of dishes
        t-=1
        if remaining[t]>=d:
            res.append(costs[t]*d)
            remaining[t]-=d
        else:
            cost = remaining[t]*costs[t]
            d-=remaining[t]
            remaining[t]=0
            while ind<n:
                a_cost, a_index = ki[ind][0],ki[ind][1]
                if remaining[a_index]>=d:
                    cost+=costs[a_index]*d
                    remaining[a_index]-=d
                    d=0
                    break
                else:
                    cost+=remaining[a_index]*costs[a_index]
                    d-=remaining[a_index]
                    remaining[a_index]=0
                ind+=1
            if d==0:
                res.append(cost)
            else:
                res.append(0)
    for i in res:
        print(i)

# -------------------------------------0-------------------------------- END=


if TestCases: 
    for _ in range(get_int()): 
        cProfile.run('main()') if testingMode else main() 
else: (cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()

def main():
    n,m = list(map(int,input().split()))
    remain = list(map(int,input().split()))
    cost = list(map(int,input().split()))

    stack = []

    for i in range(n):
        stack.append((cost[i],i))

    stack.sort()
    stack.reverse()

    for i in range(m):
        t,d = list(map(int,input().split()))
        cst = 0
        if remain[t-1] >= d:
            remain[t-1] -= d
            cst += d*cost[t-1]
        else:
            r = d - remain[t-1]
            cst += remain[t-1]*cost[t-1]
            remain[t-1] = 0
            while r != 0:
                if not stack:
                    cst = 0
                    break
                c = stack.pop()
                if remain[c[1]] >= r:
                    cst += r*cost[c[1]]
                    remain[c[1]] -= r
                    r = 0
                    if remain[c[1]] > 0:
                        stack.append(c)
                else:
                    r -= remain[c[1]]
                    cst += remain[c[1]]*cost[c[1]]
                    remain[c[1]] = 0

        print (cst)
        
main()