Submission #173429

# Submission time Handle Problem Language Result Execution time Memory
173429 2020-01-04T05:42:01 Z juggernaut Schools (IZhO13_school) C++14
75 / 100
320 ms 13964 KB
//Just try and the idea will come!
#include<bits/stdc++.h>
using namespace std;
int n,i,a,b,pr[300001],sf[300001],sum;
pair<int,int>p[300001];
multiset<int>st;
bool cmp(pair<int,int>l,pair<int,int>r){
    return l.first-l.second>r.first-r.second;
}
int main(){
    scanf("%d%d%d",&n,&a,&b);
    for(i=1;i<=n;i++)scanf("%d%d",&p[i].first,&p[i].second);
    sort(p+1,p+1+n,cmp);
    for(i=1;i<=n;i++){
        sum+=p[i].first;
        st.insert(p[i].first);
        if(i>a){
            sum-=*st.begin();
            st.erase(st.begin());
        }
        pr[i]=sum;
    }
    st.clear();
    sum=0;
    for(i=n;i>0;i--){
        sum+=p[i].second;
        st.insert(p[i].second);
        if(n+1>b+i){
            sum-=*st.begin();
            st.erase(st.begin());
        }
        sf[i]=sum;
    }
    sum=0;
    for(i=a;i<=n-b;i++)sum=max(sum,pr[i]+sf[i+1]);
    printf("%d",sum);
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&a,&b);
     ~~~~~^~~~~~~~~~~~~~~~~~~
school.cpp:12:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;i++)scanf("%d%d",&p[i].first,&p[i].second);
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 5 ms 688 KB Output is correct
13 Correct 31 ms 2808 KB Output is correct
14 Correct 54 ms 3452 KB Output is correct
15 Correct 85 ms 4828 KB Output is correct
16 Incorrect 177 ms 12536 KB Output isn't correct
17 Incorrect 224 ms 11372 KB Output isn't correct
18 Incorrect 219 ms 11256 KB Output isn't correct
19 Incorrect 243 ms 12416 KB Output isn't correct
20 Incorrect 320 ms 13964 KB Output isn't correct