func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = (int)2e5 + 100;   const int M = (int)2e6 + 100;   const int inf = (int)1e9 + 100;   int a[N];   int b[N];   int t[4 * N];   map<int, int> m[4 * N];   void add(int x, int L, int R, int pos, int val) {     t[x] = min(t[x], val);     m[x][val]++;     if (R - L == 1) {       return;     }     int c = (L + R) >> 1;     if (c > pos) {       add(2 * x + 1, L, c, pos, val);     } else {       add(2 * x + 2, c, R, pos, val);     }   }   int sum(int x, int L, int R, int l, int r) {     if (R == r && L == l) {       return t[x];     }     int c = (L + R) >> 1;     int o = inf;     if (c > l) {       o = sum(2 * x + 1, L, c, l, min(c, r));     }     if (c < r) {       o = min(o, sum(2 * x + 2, c, R, max(l, c), r));     }     return o;   }   int del(int x, int L, int R, int l, int r, int val) {     if (R - L == 1) {       m[x][val]--;       if (!m[x][val]) m[x].erase(val);       if (m[x].size())         t[x] = m[x].begin()->first;       else         t[x] = inf;       return L;     }     int c = (L + R) >> 1;     int o = -1;     m[x][val]--;     if (!m[x][val]) m[x].erase(val);     if (c > l && m[2 * x + 1].count(val)) {       o = del(2 * x + 1, L, c, l, min(c, r), val);     }     if (c < r && m[2 * x + 2].count(val) && o == -1) {       o = del(2 * x + 2, c, R, max(l, c), r, val);     }     t[x] = min(t[2 * x + 1], t[2 * x + 2]);     return o;   }   void print(int x, int L, int R) {     cout << x <<     << L <<     << R <<  :  << t[x] <<   n ;     for (auto j : m[x]) {       cout << j.first <<     << j.second <<   n ;     }     cout <<   n ;     if (R - L == 1) return;     int c = (L + R) >> 1;     print(2 * x + 1, L, c);     print(2 * x + 2, c, R);   }   int main() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     srand(time(0));     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, M, i;     cin >> n >> M;     vector<int> v;     for ((i) = 0; (i) < (n); (i)++) {       cin >> a[i];       v.push_back(a[i]);     }     for ((i) = 0; (i) < (4 * N); (i)++) {       t[i] = inf;     }     for ((i) = 0; (i) < (M); (i)++) {       cin >> b[i];       v.push_back(b[i]);     }     sort((v).begin(), (v).end()),         v.resize(unique((v).begin(), (v).end()) - v.begin());     map<int, int> m;     for ((i) = 0; (i) < (v.size()); (i)++) {       m[v[i]] = i;     }     int R = v.size();     for ((i) = 0; (i) < (M); (i)++) {       int p;       cin >> p;       add(0, 0, R, m[b[i]], p);     }     int ma = 0;     vector<pair<int, long long> > g;     for ((i) = n - 1; (i) >= 0; (i)--) {       if (a[i] > ma) {         ma = a[i];         g.push_back({i, a[i]});       } else {         g[g.size() - 1].second += a[i];       }     }     int ans = 0;     for ((i) = 0; (i) < (g.size()); (i)++) {       int x = sum(0, 0, R, 0, m[a[g[i].first]] + 1);       int y;       while (x != inf && x <= g[i].second) {         y = del(0, 0, R, 0, m[a[g[i].first]] + 1, x);         ans++;         g[i].second -= x;         x = sum(0, 0, R, 0, m[a[g[i].first]] + 1);       }       if (x != inf) {         y = del(0, 0, R, 0, m[a[g[i].first]] + 1, x);         add(0, 0, R, y, x - g[i].second);       }     }     cout << ans;   }   