Submission #47566

#TimeUsernameProblemLanguageResultExecution timeMemory
47566dqhungdlSchools (IZhO13_school)C++17
100 / 100
269 ms15344 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<long long,long long> ii; long long n,A,B,res=0,f1[300005],f2[300005]; ii a[300005]; multiset<long long> s; bool cmp(ii x1,ii x2) { return x1.first-x1.second>x2.first-x2.second; } int main() { ios_base::sync_with_stdio(false); //freopen("TEST.INP","r",stdin); //freopen("TEST.OUT","w",stdout); cin>>n>>A>>B; for(long long i=1;i<=n;i++) cin>>a[i].first>>a[i].second; sort(a+1,a+n+1,cmp); long long sum=0; for(long long i=1;i<=n;i++) { sum+=a[i].first; s.insert(a[i].first); if(s.size()>A) { sum-=*s.begin(); s.erase(s.begin()); } f1[i]=sum; } s.clear(); sum=0; for(long long i=n;i>=1;i--) { sum+=a[i].second; s.insert(a[i].second); if(s.size()>B) { sum-=*s.begin(); s.erase(s.begin()); } f2[i]=sum; } for(long long i=A;i<=n-B;i++) res=max(res,f1[i]+f2[i+1]); cout<<res; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:28:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(s.size()>A)
      ~~~~~~~~^~
school.cpp:41:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(s.size()>B)
      ~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...