# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100281 | choikiwon | Schools (IZhO13_school) | C++17 | 185 ms | 7664 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;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 300010;
int N, M, S;
pii P[MN];
priority_queue<int> pq;
ll dp[MN], cost;
int main() {
scanf("%d %d %d", &N, &M, &S);
for(int i = 0; i < N; i++) {
scanf("%d %d", &P[i].first, &P[i].second);
}
sort(P, P + N);
reverse(P, P + N);
for(int i = 0; i < M; i++) {
pq.push(P[i].second - P[i].first);
cost += P[i].first;
}
dp[M - 1] = cost;
for(int i = M; i < M + S; i++) {
pq.push(P[i].second - P[i].first);
cost += P[i].first;
cost += pq.top(); pq.pop();
dp[i] = cost;
}
ll ans = dp[M + S - 1];
while(!pq.empty()) pq.pop();
for(int i = M + S; i < N; i++) pq.push(P[i].second);
cost = 0;
for(int i = M + S - 2; i >= M - 1; i--) {
pq.push(P[i + 1].second);
cost += pq.top(); pq.pop();
ans = max(ans, dp[i] + cost);
}
printf("%lld", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |