# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
951969 | GrandTiger1729 | Cake 3 (JOI19_cake3) | C++17 | 1 ms | 348 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;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n, K;
cin >> n >> K;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++)
{
cin >> a[i].second >> a[i].first;
}
sort(a.begin(), a.end());
long long ans = 0;
for (int i = 0; i < n; i++)
{
long long cur = 0;
priority_queue<int, vector<int>, greater<>> pq;
for (int j = i; j < n; j++)
{
pq.push(a[j].second);
cur += a[j].second;
while (pq.size() > K)
{
cur -= pq.top();
pq.pop();
}
if (pq.size() == K)
{
ans = max(ans, cur - 2ll * (a[j].first - a[i].first));
}
}
}
cout << ans << '\n';
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... |