# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1114542 | Tsagana | Schools (IZhO13_school) | C++14 | 88 ms | 3492 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 IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define lnl long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
#define sp << ' ' <<
#define nl << '\n'
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b) {return (a.F - a.S < b.F - b.S ? 1 : 0);}
void solve () {
int n, m, s; cin >> n >> m >> s;
vector<pair<int, int>> v(n);
for (auto &i : v) cin >> i.F >> i.S;
sort(all(v), cmp);
int ans = 0;
int sum = 0;
pq<int> q;
for (int i = 0; i < n; i++) {
q.push(-v[i].S);
sum += v[i].S;
while (q.size() > s) {sum += q.top(); q.pop();}
v[i].S = sum;
}
sum = 0;
pq<int> ().swap(q);
for (int i = n-1; i >= 0; i--) {
q.push(-v[i].F);
sum += v[i].F;
while (q.size() > m) {sum += q.top(); q.pop();}
ans = max(ans, sum + (i ? v[i-1].S : 0));
}
cout << ans;
}
int main() {IOS solve(); return 0;}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |