# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
129019 | PeppaPig | Cake 3 (JOI19_cake3) | C++14 | 3 ms | 424 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>
#define long long long
#define pii pair<long, long>
#define x first
#define y second
using namespace std;
const int N = 2e5+5;
int n, m;
pii v[N];
long ans;
int main() {
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++) scanf("%lld %lld", &v[i].x, &v[i].y);
sort(v + 1, v + n + 1, [&](const pii &a, const pii &b) {
return a.y < b.y;
});
for(int i = 1; i <= n; i++) {
multiset<pii, greater<pii> > S;
for(int j = i + 1; j <= n; j++) {
if(S.size() >= m - 2) {
long ret = 0;
auto it = S.begin();
for(int i = 0; i < m - 2; i++, it++)
ret += it->x;
ret -= 2 * (v[j].y - v[i].y);
ret += v[i].x + v[j].x;
ans = max(ans, ret);
}
S.emplace(v[j]);
}
}
printf("%lld\n", ans);
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... |