# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
441213 | parsabahrami | Schools (IZhO13_school) | C++17 | 312 ms | 19064 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 int ll;
typedef pair<int, int> pii;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int N = 3e5 + 10, MOD = 1e9 + 7;
int A[N], B[N], ord[N], M[N], m, s, n; set<pii, greater<pii>> st1, st2;
int main() {
scanf("%d%d%d", &n, &m, &s);
for (int i = 1; i <= n; i++)
scanf("%d%d", &A[i], &B[i]);
/* for (int i = 1; i <= n; i++)
scanf("%d", &A[i]);
for (int i = 1; i <= n; i++)
scanf("%d", &B[i]);*/
iota(ord + 1, ord + n + 1, 1);
sort(ord + 1, ord + n + 1, [&] (int a, int b) { return A[a] > A[b]; });
ll sum = 0;
for (int i = 1; i <= m; i++) {
st1.insert({B[ord[i]] - A[ord[i]], ord[i]});
M[ord[i]] = 1;
sum += A[ord[i]];
}
for (int i = m + 1; i <= n; i++)
st2.insert({B[ord[i]], ord[i]});
int ptr = m + 1;
for (int i = 1; i <= s; i++) {
while (ptr <= n && M[ord[ptr]]) ptr++;
int c1 = (SZ(st1) ? st1.begin()->F + A[ord[ptr]] : -MOD),
c2 = (SZ(st2) ? st2.begin()->F : -MOD);
if (c2 > c1) {
//printf("1 %d ", st2.begin()->S);
M[st2.begin()->S] = 1, sum += c2;
st2.erase(st2.begin());
} else {
M[st1.begin()->S] = 1, sum += c1;
st1.erase(st1.begin());
st1.insert({B[ord[ptr]] - A[ord[ptr]], ord[ptr]}); M[ord[ptr]] = 1;
st2.erase({B[ord[ptr]], ord[ptr]});
}
//printf("%lld\n", sum);
}
printf("%lld\n", sum);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |