Submission #714029

#TimeUsernameProblemLanguageResultExecution timeMemory
714029Ahmed57Schools (IZhO13_school)C++14
100 / 100
110 ms15860 KiB
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #include <bits/stdc++.h> using namespace std; bool comp(pair<int,int>a,pair<int,int>b){ return (a.first-a.second)>(b.first-b.second); } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n,s,m; cin>>n>>s>>m; vector<pair<long long,long long>>v; for(int i = 0;i<n;i++){ long long a,b; cin>>a>>b; v.push_back({a,b}); } sort(v.begin(),v.end(),comp); priority_queue<long long> p1,p2; long long sum = 0,sum2 = 0; long long pref[n+2] = {0},suf[n+2]= {0}; for(int i= 1;i<=n;i++){ p1.push(-v[i-1].first); if(p1.size()>s){sum+=p1.top();p1.pop();} sum+=v[i-1].first; pref[i]=sum; } for(int i= n;i>=1;i--){ p2.push(-v[i-1].second); if(p2.size()>m){sum2+=p2.top();p2.pop();} sum2+=v[i-1].second; suf[i]= sum2; } cout<<endl; long long ans = -1e18; for(int i = 0;i<=n;i++){ ans = max(ans,pref[i]+suf[i+1]); } cout<<ans<<endl; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:24:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |         if(p1.size()>s){sum+=p1.top();p1.pop();}
      |            ~~~~~~~~~^~
school.cpp:30:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |         if(p2.size()>m){sum2+=p2.top();p2.pop();}
      |            ~~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...