Submission #114162

#TimeUsernameProblemLanguageResultExecution timeMemory
114162Shafin666Schools (IZhO13_school)C++14
100 / 100
242 ms11504 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define pii pair<int, int> #define nyan "(=^・ω・^=)" #define read_input freopen("in.txt","r", stdin) #define print_output freopen("out.txt","w", stdout) typedef long long ll; typedef long double ld; using namespace std; const int maxn = 3e5+10; ll f1[maxn], f2[maxn]; int main() { pii a[maxn]; int n, A, B; cin >> n >> A >> B; for(int i = 1; i <= n; i++) { cin >> a[i].first >> a[i].second; } sort(a+1, a+n+1, [] (pii a, pii b) -> bool {return a.first - a.second > b.first - b.second;}); priority_queue<int, vector<int>, greater<int>> pq; ll sum = 0;; for(int i = 1; i <= n; i++) { sum += a[i].first; pq.push(a[i].first); if(pq.size() > A) { sum -= pq.top(); pq.pop(); } f1[i] = sum; } while(! pq.empty()) pq.pop(); sum = 0; for(int i = n; i >= 1; i--) { sum += a[i].second; pq.push(a[i].second); if(pq.size() > B) { sum -= pq.top(); pq.pop(); } f2[i] = sum; } ll mx = 0; for(int i = A; i <= n-B; i++) mx = max(mx, f1[i] + f2[i+1]); cout << mx << endl; return 0; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:33:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(pq.size() > A) {
      ~~~~~~~~~~^~~
school.cpp:39:2: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
  while(! pq.empty()) pq.pop(); sum = 0;
  ^~~~~
school.cpp:39:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
  while(! pq.empty()) pq.pop(); sum = 0;
                                ^~~
school.cpp:45:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(pq.size() > B) {
      ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...