# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102522 | Bruteforceman | Cake 3 (JOI19_cake3) | C++11 | 4059 ms | 428 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 pair <int, int> pii;
pii a[100010];
int n, m;
const long long inf = 1e18;
long long query(int i, int j) {
vector <int> v;
long long ans = -2 * (a[j].first - a[i].first);
for(int x = i; x <= j; x++) {
v.push_back(a[x].second);
}
sort(v.begin(), v.end(), greater <int> ());
for(int i = 0; i < m; i++) {
ans += v[i];
}
return ans;
}
int main(int argc, char const *argv[])
{
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++) {
int p, q;
scanf("%d %d", &p, &q);
a[i] = pii(q, p);
}
sort(a + 1, a + n + 1);
int l = 1;
long long ans = LLONG_MIN;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= i; j++) {
if((i - j + 1) >= m) {
ans = max(ans, query(j, i));
}
}
}
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... |