Submission #90804

# Submission time Handle Problem Language Result Execution time Memory
90804 2018-12-24T13:19:11 Z Aydarov03 Schools (IZhO13_school) C++14
100 / 100
515 ms 35160 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define fr first
#define sc second
using namespace std;

vector < pii > v;

main()
{
    multiset < ll > rz;
    multiset < pii> v1 , v2;

    ll x , y;
    ll n , m , s , ans = 0;
    cin >> n >> m >> s;



    for(int i = 1; i <= n; i++)
    {
        cin >> x >> y;
        v.push_back( {x , y} );
    }

    sort( v.rbegin() , v.rend() );


    for(int i = 0; i < m; i++)
    {
        ans += v[i].fr;
        rz.insert( (v[i].fr - v[i].sc) );
    }

    for(int i = m; i < n; i++)
    {
        v1.insert( v[i] );
        v2.insert( {v[i].sc , v[i].fr} );
    }



    for(int i = s; i >= 1; i--)
    {
        pii x = *v1.rbegin();
        pii y = *v2.rbegin();
        int raz = -*rz.begin();

        if( x.fr + raz > y.fr )
        {
            ans += (x.fr + raz);
            rz.erase( rz.begin() );
            rz.insert(  x.fr - x.sc );
            v1.erase( v1.find( {x.fr , x.sc}) );
            v2.erase( v2.find( {x.sc , x.fr} ) );
        }
        else
        {
            ans += y.fr;
            v2.erase( v2.find( {y.fr , y.sc } ) );
            v1.erase( v1.find( {y.sc , y.fr } ) );
        }
    }

    cout << ans;
}

Compilation message

school.cpp:10:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 372 KB Output is correct
4 Correct 2 ms 408 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 7 ms 1072 KB Output is correct
8 Correct 5 ms 1072 KB Output is correct
9 Correct 5 ms 1072 KB Output is correct
10 Correct 5 ms 1072 KB Output is correct
11 Correct 8 ms 1200 KB Output is correct
12 Correct 8 ms 1200 KB Output is correct
13 Correct 37 ms 3172 KB Output is correct
14 Correct 150 ms 10896 KB Output is correct
15 Correct 277 ms 22976 KB Output is correct
16 Correct 512 ms 24188 KB Output is correct
17 Correct 368 ms 24672 KB Output is correct
18 Correct 379 ms 27144 KB Output is correct
19 Correct 434 ms 29964 KB Output is correct
20 Correct 515 ms 35160 KB Output is correct