Submission #972667

#TimeUsernameProblemLanguageResultExecution timeMemory
972667imarnSchools (IZhO13_school)C++14
100 / 100
105 ms11468 KiB
#include<bits/stdc++.h> #define f first #define s second #define pb push_back #define pii pair<int,int> #define ll long long #define sz(x) (ll)x.size() using namespace std; bool cmp(pii a,pii b){ return a.f-a.s>b.f-b.s; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n,m,s;cin>>n>>m>>s;pii a[n+1]; for(int i=1;i<=n;i++)cin>>a[i].f>>a[i].s; sort(a+1,a+n+1,cmp); ll dl[n+2]={0},dr[n+2]={0},sum=0; priority_queue<int,vector<int>,greater<int>>q; for(int i=1;i<=n;i++){ sum+=a[i].f;q.push(a[i].f); while(!q.empty()&&q.size()>m)sum-=q.top(),q.pop(); dl[i]=sum; }sum=0;while(!q.empty())q.pop(); for(int i=n;i>=1;i--){ sum+=a[i].s;q.push(a[i].s); while(!q.empty()&&q.size()>s)sum-=q.top(),q.pop(); dr[i]=sum; }ll ans=0; for(int i=0;i<=n;i++)if(i>=m&&n-i>=s)ans=max(ans,dl[i]+dr[i+1]); cout<<ans; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:21:35: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |         while(!q.empty()&&q.size()>m)sum-=q.top(),q.pop();
      |                           ~~~~~~~~^~
school.cpp:26:35: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |         while(!q.empty()&&q.size()>s)sum-=q.top(),q.pop();
      |                                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...