# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
524090 | vishesh312 | Schools (IZhO13_school) | C++17 | 106 ms | 15100 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;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)(x).size()
using ll = long long;
#define int ll
const int mod = 1e9+7;
void solve(int tc) {
int n, m, s;
cin >> n >> m >> s;
vector<pair<int, int>> v(n);
for (auto &[a, b]: v)
cin >> a >> b;
sort(all(v), [] (pair<int, int> a, pair<int, int> b) {
return (a.first - a.second) > (b.first - b.second);
});
priority_queue<int, vector<int>, greater<>> pq;
vector<int> asum(n), bsum(n);
int cur = 0;
for (int i = 0; i < n; ++i) {
asum[i] = v[i].first + (i ? asum[i-1] : 0);
pq.push(v[i].first);
++cur;
while (cur > m) {
asum[i] -= pq.top();
pq.pop();
--cur;
}
}
int ans = asum[n-1];
cur = 0;
pq = priority_queue<int, vector<int>, greater<>>();
for (int i = n-1; i >= 0; --i) {
bsum[i] = v[i].second + (i < n-1 ? bsum[i+1] : 0);
pq.push(v[i].second);
++cur;
while (cur > s) {
bsum[i] -= pq.top();
pq.pop();
--cur;
}
ans = max(ans, (i ? asum[i-1] : 0) + bsum[i]);
}
cout << ans << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) solve(i);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |