# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
114162 | Shafin666 | Schools (IZhO13_school) | C++14 | 242 ms | 11504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |