func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m;   const int MAX_N = 100005;   long long cost[MAX_N];   int r[MAX_N];   struct dish {     int idx, cnt;     long long c;     bool operator<(const dish &d) const {       if (c != d.c) return c < d.c;       return idx < d.idx;     }   };   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> r[i];     for (int i = 0; i < n; ++i) cin >> cost[i];     multiset<dish> s;     for (int i = 0; i < n; ++i) {       s.insert({i, r[i], cost[i]});     }     vector<long long> ans(m);     for (int i = 0; i < m; ++i) {       long long tempCost = 0;       int dIdx, dCnt;       cin >> dIdx >> dCnt;       --dIdx;       auto it = s.find({dIdx, r[dIdx], cost[dIdx]});       if (it != s.end()) {         dish d = *it;         s.erase(it);         int buy = min(dCnt, r[dIdx]);         d.cnt -= buy;         r[dIdx] -= buy;         dCnt -= buy;         tempCost += d.c * buy;         if (d.cnt) s.insert(d);       }       while (!s.empty() && dCnt) {         auto it = s.begin();         dish d = *it;         s.erase(it);         int buy = min(dCnt, d.cnt);         d.cnt -= buy;         r[d.idx] -= buy;         dCnt -= buy;         tempCost += d.c * buy;         if (d.cnt) s.insert(d);       }       if (dCnt) break;       ans[i] = tempCost;     }     for (int i = 0; i < m; ++i) cout << ans[i] <<   n ;     return 0;   }   