# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
573992 | YouAreMyGalaxy | Cake 3 (JOI19_cake3) | C++17 | 4083 ms | 6628 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.
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 2e5;
int id[N + 1], a[N + 1], b[N + 1];
int n, m;
long long res = -1e18;
void read()
{
cin >> n >> m;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i] >> b[i];
id[i] = i;
}
sort(id + 1, id + n + 1, [&](const int &x, const int &y)
{
return b[x] < b[y];
});
}
void solve()
{
for (int i = 1; i <= n; ++ i)
{
priority_queue<int, vector<int>, greater<int> > PQ;
long long sum = 0;
int l = id[i];
for (int j = i; j <= n; ++ j)
{
int r = id[j];
sum += a[r];
PQ.push(a[r]);
if (PQ.size() > m)
{
sum -= PQ.top();
PQ.pop();
}
if (PQ.size() == m)
{
res = max(res, sum - 2 * (b[r] - b[l]));
}
}
}
cout << res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case #" << __ << ":" << '\n';
read();
solve();
}
}
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... |