# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
249443 | shenxy | Cake 3 (JOI19_cake3) | C++11 | 4073 ms | 6556 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 <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>
using namespace std;
typedef pair<long long, long long> ii;
int main() {
int N, M;
scanf("%d %d", &N, &M);
ii CV[N];
long long ans, bans = -1000000000000000000LL;
for (int i = 0; i < N; ++i) scanf("%lld %lld", &CV[i].second, &CV[i].first);
sort(CV, CV + N);
for (int i = 0; i <= N - M; ++i) {
priority_queue< long long, vector<long long>, greater<long long> > pq;
ans = 0;
for (int j = i; j < i + M; ++j) pq.push(CV[j].second), ans += CV[j].second;
bans = max(bans, ans + 2 * CV[i].first - 2 * CV[i + M - 1].first);
for (int j = i + M; j < N; ++j) {
if (CV[j].second > pq.top()) {
ans += CV[j].second - pq.top();
pq.pop();
pq.push(CV[j].second);
}
bans = max(bans, ans + 2 * CV[i].first - 2 * CV[j].first);
}
}
printf("%lld", bans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |