# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
146435 | jwvg0425 | Cake 3 (JOI19_cake3) | C++17 | 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 <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int main()
{
int n, m;
scanf("%d %d", &n, &m);
vector<ii64> cakes(n);
for (int i = 0; i < n; i++)
scanf("%lld %lld", &cakes[i].xx, &cakes[i].yy);
sort(all(cakes), [](const ii& l, const ii& r)
{
if (l.yy == r.yy)
return l.xx < r.xx;
return l.yy < r.yy;
});
i64 ans = 0;
for (int sc = 0; sc < n; sc++)
{
multiset<i64> largest;
i64 sum = 0;
for (int bc = sc; bc < n; bc++)
{
if (largest.size() < m)
{
largest.insert(cakes[bc].xx);
sum += cakes[bc].xx;
}
else if(*largest.begin() < cakes[bc].xx)
{
sum += cakes[bc].xx;
sum -= *largest.begin();
largest.erase(largest.begin());
largest.insert(cakes[bc].xx);
}
if (largest.size() == m && sum - 2 * (cakes[bc].yy - cakes[sc].yy) > ans)
ans = sum - 2 * (cakes[bc].yy - cakes[sc].yy);
}
}
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... |