3702 2023. 03. 02 11:50:21 Ancsa Szemetessor cpp11 Accepted 100/100 414ms 37012 KiB
#include <bits/stdc++.h>

/*
5 12
66 73 69 79 78
2 50
3 69
0 1
0 12
2 20
0 23
1 44
1 30
4 12
4 3
4 63
0 10

kimenet: 170
*/



using namespace std;

int main()
{
    long long int kszam, napsz;
    cin>>kszam>>napsz;
    vector<pair<long long int, long long int>> szemet(napsz);
    vector<int> kapac(kszam);

    for(long long int i=0;i<kszam;i++)
        cin>>kapac.at(i);

    for(long long int i=0;i<napsz;i++)
    {
        cin>>szemet.at(i).first>>szemet.at(i).second;
    }
/*
    for(int x:kapac)
        cout<<x<<" ";

    cout<<endl;

    for(pair<long long int,long long int> par: szemet)
        cout<<par.first<<" "<<par.second<<endl;
*/
    map<long long int,long long int> tarolo;

    long long int fizetni=0;
    for(pair<long long int,long long int> par: szemet)
    {
        tarolo[par.first]+=par.second;
        if (tarolo[par.first]>kapac.at(par.first))
        {
           tarolo[par.first]-=par.second;
           fizetni+=kapac.at(par.first)-tarolo.at(par.first);
           tarolo.at(par.first)=par.second;
        }

    }
    /*
    cout<<"A map tartalma: \n\n";
    for(pair<int,int> elem:tarolo)
        cout<<elem.first<<" "<<elem.second<<endl;
*/

    for(pair<long long int,long long int> elem:tarolo)
    {
        if(elem.second>0)
            fizetni+=kapac.at(elem.first)-tarolo.at(elem.first);
    }

    cout<<fizetni;


    //cout << "Hello world!" << endl;
    return 0;
}
Subtask Sum Test Verdict Time Memory
subtask1 0/0
1 Accepted 3ms 1812 KiB
2 Accepted 3ms 2056 KiB
subtask2 17/17
3 Accepted 3ms 2300 KiB
4 Accepted 2ms 2516 KiB
5 Accepted 2ms 2564 KiB
6 Accepted 2ms 2528 KiB
7 Accepted 2ms 2776 KiB
8 Accepted 2ms 2740 KiB
9 Accepted 3ms 2984 KiB
10 Accepted 2ms 3228 KiB
11 Accepted 2ms 3276 KiB
subtask3 25/25
12 Accepted 138ms 9572 KiB
13 Accepted 174ms 9660 KiB
14 Accepted 201ms 10020 KiB
15 Accepted 221ms 10512 KiB
16 Accepted 244ms 11564 KiB
17 Accepted 328ms 23560 KiB
18 Accepted 414ms 36768 KiB
19 Accepted 414ms 36712 KiB
20 Accepted 414ms 37012 KiB
subtask4 20/20
21 Accepted 180ms 11456 KiB
22 Accepted 228ms 15916 KiB
23 Accepted 182ms 11564 KiB
24 Accepted 219ms 13808 KiB
25 Accepted 189ms 11668 KiB
26 Accepted 300ms 21304 KiB
27 Accepted 372ms 27128 KiB
28 Accepted 377ms 27776 KiB
29 Accepted 361ms 27116 KiB
30 Accepted 338ms 26532 KiB
subtask5 38/38
31 Accepted 3ms 4792 KiB
32 Accepted 2ms 4880 KiB
33 Accepted 3ms 5028 KiB
34 Accepted 3ms 5104 KiB
35 Accepted 17ms 5356 KiB
36 Accepted 195ms 11332 KiB
37 Accepted 372ms 19004 KiB
38 Accepted 368ms 17688 KiB
39 Accepted 375ms 20916 KiB
40 Accepted 377ms 25520 KiB
41 Accepted 407ms 28244 KiB
42 Accepted 384ms 26664 KiB