Submission #83708

#TimeUsernameProblemLanguageResultExecution timeMemory
83708mra2322001Schools (IZhO13_school)C++14
100 / 100
129 ms8308 KiB
#include <bits/stdc++.h> #define f0(i, n) for(int i(0); i < (n); i++) #define f1(i, n) for(int i(1); i <= n; i++) using namespace std; typedef long long ll; const int N = 300002; int n, m, s; ll ans1[N], ans2[N]; pair <int, int> a[N]; int main(){ ios_base::sync_with_stdio(0); cin >> n >> m >> s; f1(i, n) cin >> a[i].first >> a[i].second; sort(a + 1, a + n + 1, [&](pair <int, int> a1, pair <int, int> a2){ return a1.first - a1.second > a2.first - a2.second; }); priority_queue <int, vector <int>, greater <int> > q; if(m > 0){ f1(i, n){ if(i <= m){ ans1[i] = ans1[i - 1] + a[i].first; q.push(a[i].first); } else{ ans1[i] = max(ans1[i - 1] - q.top() + a[i].first, ans1[i - 1]); if(q.top() <= a[i].first){ q.pop(); q.push(a[i].first); } } } } while(q.size()) q.pop(); if(s > 0){ for(int i = n; i >= 1; i--){ if(n - i + 1 <= s){ ans2[i] = ans2[i + 1] +a[i].second; q.push(a[i].second); } else{ ans2[i] = max(ans2[i + 1], ans2[i + 1] - q.top() + a[i].second); if(ans2[i] != ans2[i + 1]){ q.pop(); q.push(a[i].second); } } } } ll ans = 0; f0(i, n + 1){ if(i >= m && n - i >= s) ans = max(ans, ans1[i] + ans2[i + 1]); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...