Submission #348812

# Submission time Handle Problem Language Result Execution time Memory
348812 2021-01-15T19:22:43 Z nicolaalexandra Schools (IZhO13_school) C++14
75 / 100
416 ms 15512 KB
#include <bits/stdc++.h>
#define DIM 300010
using namespace std;

pair <int,int> v[DIM];
int a[DIM],b[DIM],pref[DIM],suf[DIM];
multiset <int> s;
int n,nra,nrb,i;

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n>>nra>>nrb;
    for (i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        v[i] = make_pair(b[i]-a[i],i);
    }

    sort (v+1,v+n+1);

    int sum = 0;
    for (i=1;i<=nra;i++){
        sum += a[v[i].second];
        s.insert(a[v[i].second]);
    }

    pref[nra] = sum;
    for (i=nra+1;i<=n;i++){
        sum += a[v[i].second];

        s.insert(a[v[i].second]);

        /// scad minimul din set
        sum -= *s.begin();
        s.erase(s.begin());

        pref[i] = sum;
    }


    sum = 0;
    s.clear();
    for (i=n-nrb+1;i<=n;i++){
        sum += b[v[i].second];
        s.insert(b[v[i].second]);
    }

    suf[n-nrb+1] = sum;

    for (i=n-nrb;i;i--){
        sum += b[v[i].second];
        s.insert(b[v[i].second]);

        sum -= *s.begin();
        s.erase(s.begin());

        suf[i] = sum;
    }

    int sol = 0;
    for (i=0;i<=n;i++)
        sol = max (sol,pref[i] + suf[i+1]);
    cout<<sol;


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 4 ms 492 KB Output is correct
8 Correct 5 ms 748 KB Output is correct
9 Correct 5 ms 620 KB Output is correct
10 Correct 6 ms 620 KB Output is correct
11 Correct 5 ms 620 KB Output is correct
12 Correct 5 ms 748 KB Output is correct
13 Correct 38 ms 2924 KB Output is correct
14 Correct 72 ms 3948 KB Output is correct
15 Correct 131 ms 6168 KB Output is correct
16 Incorrect 249 ms 13292 KB Output isn't correct
17 Incorrect 285 ms 12364 KB Output isn't correct
18 Incorrect 308 ms 12524 KB Output isn't correct
19 Incorrect 348 ms 13532 KB Output isn't correct
20 Incorrect 416 ms 15512 KB Output isn't correct