# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
445178 | ritul_kr_singh | Schools (IZhO13_school) | C++17 | 121 ms | 10164 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>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'
int n, m, s, sum, ans;
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> s;
array<int, 2> a[n];
for(auto &i : a) cin >> i[0] >> i[1];
sort(a, a+n, [&](auto &i, auto &j){
return i[0] - i[1] < j[0] - j[1];
});
priority_queue<int> q;
for(int i=0; i<n; ++i){
q.push(-a[i][1]);
sum += a[i][1];
while((int)q.size() > s) sum += q.top(), q.pop();
a[i][1] = sum;
}
priority_queue<int> ().swap(q);
sum = 0;
for(int i=n; --i; ){
q.push(-a[i][0]);
sum += a[i][0];
while((int)q.size() > m) sum += q.top(), q.pop();
ans = max(ans, sum + a[i-1][1]);
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |