#include <bits/stdc++.h>   const int N = 1e5 + 5;   const int OO = 1e9 + 7;   using namespace std;   long long n, m, dishes[N], cost[N];   priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                  greater<pair<long long, long long>>>       q;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> dishes[i];     for (int i = 0; i < n; i++) cin >> cost[i], q.push({cost[i], i});     for (int i = 0; i < m; i++) {       long long kind, numofdishes, COST = 0;       cin >> kind >> numofdishes;       kind--;       if (numofdishes <= dishes[kind]) {         COST += (numofdishes * cost[kind]);         dishes[kind] -= numofdishes;         cout << COST <<   n ;       } else {         COST += (dishes[kind] * cost[kind]);         numofdishes -= dishes[kind];         dishes[kind] = 0;         while (!q.empty() && numofdishes > 0) {           if (dishes[q.top().second] <= 0) {             q.pop();             continue;           }           if (numofdishes <= dishes[q.top().second]) {             COST += (numofdishes * q.top().first);             dishes[q.top().second] -= numofdishes;             numofdishes = 0;           } else {             COST += (dishes[q.top().second] * q.top().first);             numofdishes -= dishes[q.top().second];             dishes[q.top().second] = 0;           }           if (dishes[q.top().second] <= 0) {             q.pop();             continue;           }         }         if (numofdishes > 0)           cout << 0 <<   n ;         else           cout << COST <<   n ;       }     }   }   