Submission #209617

#TimeUsernameProblemLanguageResultExecution timeMemory
209617MohamedAhmed0Schools (IZhO13_school)C++14
100 / 100
153 ms17512 KiB
#include <bits/stdc++.h> using namespace std ; const int MAX = 300000 + 10 ; long long M[MAX] , S[MAX] ; long long prefM[MAX] , suffS[MAX] ; int n , m , s ; int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n>>m>>s ; vector< pair<int , int> >vp ; for(int i = 0 ; i < n ; ++i) { cin>>M[i]>>S[i] ; vp.push_back({M[i]-S[i] , i}) ; } sort(vp.rbegin() , vp.rend()) ; priority_queue< long long , vector<long long> , greater<long long> >q ; long long sum = 0 ; for(int i = 0 ; i < n ; ++i) { int idx = vp[i].second ; if(q.size() < m) { sum += M[idx] ; q.push(M[idx]) ; } else if(q.top() < M[idx]) { sum -= q.top() ; q.pop() ; sum += M[idx] ; q.push(M[idx]) ; } prefM[i] = sum ; } while(q.size() > 0) q.pop() ; sum = 0 ; for(int i = n-1 ; i >= 0 ; --i) { int idx = vp[i].second ; if(q.size() < s) { sum += S[idx] ; q.push(S[idx]) ; } else if(q.top() < S[idx]) { sum -= q.top() ; q.pop() ; sum += S[idx] ; q.push(S[idx]) ; } suffS[i] = sum ; } long long ans = suffS[0] ; for(int i = 0 ; i < n ; ++i) ans = max(ans , prefM[i] + suffS[i+1]) ; return cout<<ans<<"\n" , 0 ; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:28:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(q.size() < m)
      ~~~~~~~~~^~~
school.cpp:48:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(q.size() < s)
      ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...