22662023-01-08 10:42:101478Szemetessorcpp17Accepted 100/10082ms7892 KiB
#include <bits/stdc++.h>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

int main()
{
    fast_cin();
    //ifstream cin("in.txt");

    int n;
    cin >> n;

    int k;
    cin >> k;

    vector<int> capacity(n);
    for (int i = 0; i < n; i++)
    {
        cin >> capacity[i];
    }

    vector<int> full(n);
    long long ans = 0;

    for (int i = 0; i < k; i++)
    {
        int ind;
        cin >> ind;

        int val;
        cin >> val;

        if (full[ind] + val <= capacity[ind])
        {
            full[ind] += val;
        }
        else
        {
            ans += capacity[ind] - full[ind];
            full[ind] = val;
        }
    }


    for (int i = 0; i < n; i++)
    {
        if (full[i] != 0)
        {
            ans += capacity[i] - full[i];
        }
    }

    cout << ans;

    return 0;
}


SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted2ms2048 KiB
subtask217/17
3Accepted2ms2256 KiB
4Accepted2ms2460 KiB
5Accepted2ms2676 KiB
6Accepted2ms2884 KiB
7Accepted2ms3104 KiB
8Accepted2ms3196 KiB
9Accepted2ms3304 KiB
10Accepted2ms3412 KiB
11Accepted2ms3476 KiB
subtask325/25
12Accepted41ms3480 KiB
13Accepted41ms3684 KiB
14Accepted45ms3888 KiB
15Accepted46ms4084 KiB
16Accepted48ms4348 KiB
17Accepted64ms5744 KiB
18Accepted78ms7760 KiB
19Accepted78ms7712 KiB
20Accepted78ms7752 KiB
subtask420/20
21Accepted46ms4896 KiB
22Accepted48ms5480 KiB
23Accepted46ms4720 KiB
24Accepted50ms4948 KiB
25Accepted48ms4720 KiB
26Accepted63ms5984 KiB
27Accepted78ms7416 KiB
28Accepted78ms7540 KiB
29Accepted81ms7540 KiB
30Accepted74ms7560 KiB
subtask538/38
31Accepted2ms4792 KiB
32Accepted2ms4644 KiB
33Accepted2ms4640 KiB
34Accepted2ms4648 KiB
35Accepted6ms4980 KiB
36Accepted46ms4964 KiB
37Accepted81ms7748 KiB
38Accepted82ms7748 KiB
39Accepted82ms7744 KiB
40Accepted81ms7744 KiB
41Accepted79ms7744 KiB
42Accepted79ms7892 KiB