# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
129008 | PeppaPig | Cake 3 (JOI19_cake3) | C++14 | 3 ms | 376 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<int, int>
#define x first
#define y second
using namespace std;
const int N = 2e5+5;
int n, m;
long v[N], c[N], ans;
int main() {
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++) scanf("%lld %lld", v + i, c + i);
for(int i = 1; i <= n; i++) {
multiset<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 * (c[j] - c[i]);
ret += v[i] + v[j];
ans = max(ans, ret);
}
S.emplace(v[j], c[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... |