func_code_string: #include <bits/stdc++.h>   using namespace std;   #pragma GCC diagnostic ignored  -Wmissing-declarations    inline int safe_mul(const int x, const int y)       __attribute__((warn_unused_result));   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<int> a(n);     for (int& x : a) cin >> x;     int const inf = 200001;     vector<vector<int>> te(inf + 2);     for (int i = 0; i < m; ++i) {       int d, t;       cin >> d >> t;       te[d].push_back(t - 1);     }     int l = 0;     int r = inf;     while (r - l > 1) {       int mid = (l + r) >> 1;       auto tmpa = a;       int val = mid;       int sum = 0;       for (int i = mid; i >= 1; --i) {         for (int x : te[i]) {           int cur = min(val, i);           int need = min(tmpa[x], cur);           cur -= need;           val = min(val, cur);           tmpa[x] -= need;           sum += need;         }       }       if (accumulate(begin(tmpa), end(tmpa), 0LL) * 2 <= mid - sum)         r = mid;       else         l = mid;     }     if (r == inf) {       int mid = inf - 1;       auto tmpa = a;       int val = mid;       int64_t sum = 0;       for (int i = mid; i >= 1; --i) {         for (int x : te[i]) {           int cur = min(val, i);           int need = min(tmpa[x], cur);           cur -= need;           val = min(val, cur);           tmpa[x] -= need;           sum += need;         }       }       sum += accumulate(begin(tmpa), end(tmpa), 0LL) * 2;       cout << sum << endl;     } else {       cout << r << endl;     }   }   