Submission #673568

# Submission time Handle Problem Language Result Execution time Memory
673568 2022-12-21T06:56:42 Z ReLice Schools (IZhO13_school) C++17
35 / 100
191 ms 20560 KB
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define pb push_back
#define fr first
#define sc second
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll N = 4e5 + 10 ;
const ll mod=1e9+7;
ll pr[N],suf[N];
void solve(){
    ll n,i,x,y,l,r,mx=-1;
    ll m,k,sum=0,c=0,j,b;
    cin>>n>>m>>k;
    vector <pair<ll,pair<ll,ll>>> vec;
    vector <ll> v,v2;
    set<ll> st,st2;
    for(i=0;i<n;i++){
        cin>>x>>y;
        vec.pb({y-x,{x,y}});
    }
    sort(vec.begin(),vec.end());
    v.pb(0);
    v2.pb(0);
    for(i=0;i<n;i++){
        v.pb(vec[i].sc.fr);
        v2.pb(vec[i].sc.sc);
    }
    if(!m && !k){
        cout<<0<<endl;
        return;
    }
    if(!k){
        sort(v.rbegin(),v.rend());
        for(i=0;i<m;i++) sum+=v[i];
        cout<<sum<<endl;
        return;
    }
    if(!m){
        sort(v2.rbegin(),v2.rend());
        for(i=0;i<m;i++) sum+=v[i];
        cout<<sum<<endl;
        return;
    }
    for(i=1;i<=m;i++){
        st.insert(v[i]);
        sum+=v[i];
    }
    pr[m]=sum;
    for(i=m+1;i<=n;i++){
        if(v[i]>*st.begin()){
            sum-=*st.begin();
            st.erase(st.begin());
            sum+=v[i];
            st.insert(v[i]);
        }
        pr[i]=sum;
    }
    sum=0;
    for(i=n;i>n-k;i--){
        st2.insert(v2[i]);
        sum+=v2[i];
    }
    suf[n-k+1]=sum;
    for(i=n-k;i>0;i--){
        if(v2[i]>*st2.begin()){
            sum-=*st2.begin();
            st2.erase(st2.begin());
            sum+=v2[i];
            st2.insert(v2[i]);
        }
        suf[i]=sum;
    }
    for(i=m;i<=n-k;i++){
        mx=max(mx,pr[i]+suf[i+1]);
    }
    cout<<mx<<endl;
}
main(){
    //fre("");
    //start();
    ll t=1;
    //cin>>t;
    while(t--)solve();

}

Compilation message

school.cpp: In function 'void solve()':
school.cpp:17:16: warning: unused variable 'l' [-Wunused-variable]
   17 |     ll n,i,x,y,l,r,mx=-1;
      |                ^
school.cpp:17:18: warning: unused variable 'r' [-Wunused-variable]
   17 |     ll n,i,x,y,l,r,mx=-1;
      |                  ^
school.cpp:18:18: warning: unused variable 'c' [-Wunused-variable]
   18 |     ll m,k,sum=0,c=0,j,b;
      |                  ^
school.cpp:18:22: warning: unused variable 'j' [-Wunused-variable]
   18 |     ll m,k,sum=0,c=0,j,b;
      |                      ^
school.cpp:18:24: warning: unused variable 'b' [-Wunused-variable]
   18 |     ll m,k,sum=0,c=0,j,b;
      |                        ^
school.cpp: At global scope:
school.cpp:84:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   84 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Incorrect 3 ms 596 KB Output isn't correct
8 Correct 4 ms 660 KB Output is correct
9 Incorrect 4 ms 660 KB Output isn't correct
10 Incorrect 4 ms 660 KB Output isn't correct
11 Incorrect 4 ms 660 KB Output isn't correct
12 Incorrect 4 ms 660 KB Output isn't correct
13 Incorrect 26 ms 3204 KB Output isn't correct
14 Incorrect 51 ms 5628 KB Output isn't correct
15 Incorrect 94 ms 11036 KB Output isn't correct
16 Correct 128 ms 10936 KB Output is correct
17 Incorrect 139 ms 12500 KB Output isn't correct
18 Incorrect 150 ms 13580 KB Output isn't correct
19 Incorrect 161 ms 14380 KB Output isn't correct
20 Incorrect 191 ms 20560 KB Output isn't correct