# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47563 | kuroni | Schools (IZhO13_school) | C++14 | 174 ms | 8152 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 <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int N = 300005;
struct SCity
{
int a, b;
} s[N];
int n;
unsigned int a, b;
long long pre[N], suf[N];
priority_queue<int, vector<int>, greater<int>> pq;
int main()
{
scanf("%d%u%u", &n, &a, &b);
for (int i = 1; i <= n; i++)
scanf("%d%d", &s[i].a, &s[i].b);
sort(s + 1, s + n + 1, [](const SCity &a, const SCity &b) { return a.a - a.b > b.a - b.b; });
for (int i = 1; i <= n; i++)
{
if (pq.size() < a)
{
pre[i] = pre[i - 1] + s[i].a;
pq.push(s[i].a);
}
else if (pq.top() < s[i].a)
{
pre[i] = pre[i - 1] - pq.top() + s[i].a;
pq.pop();
pq.push(s[i].a);
}
else
pre[i] = pre[i - 1];
}
while (!pq.empty())
pq.pop();
for (int i = n; i >= 1; i--)
{
if (pq.size() < b)
{
suf[i] = suf[i + 1] + s[i].b;
pq.push(s[i].b);
}
else if (pq.top() < s[i].b)
{
suf[i] = suf[i + 1] - pq.top() + s[i].b;
pq.pop();
pq.push(s[i].b);
}
else
suf[i] = suf[i + 1];
}
while (!pq.empty())
pq.pop();
long long ans = 0;
for (int i = 0; i <= n; i++)
ans = max(ans, pre[i] + suf[i + 1]);
printf("%lld", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |