# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
263417 | mjkocijan | Cake 3 (JOI19_cake3) | C++14 | 240 ms | 632 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;
#define X first
#define Y second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> ii;
#define MAXN 2020
#define INF 1001001001001001001LL
int n, m;
ll _v[MAXN], c[MAXN];
vector<ii> v;
multiset<ll> s;
ll reza = -INF;
int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%lld%lld", &_v[i], &c[i]);
v.pb({c[i], _v[i]});
}
sort(v.begin(), v.end());
for (int i = 0; i <= n - m; i++) {
s.clear();
ll suma = 0;
for (int j = i; j < i + m; j++) {
s.insert(v[j].Y);
suma += v[j].Y;
}
//cout << suma - (v[i + m - 1].X - v[i].X) * 2LL<<endl;
reza = max(reza, suma - (v[i + m - 1].X - v[i].X) * 2LL);
for (int j = i + m; j < n; j++) {
if ((*s.begin()) < v[j].Y) {
//cout << (*s.begin()) <<'.'<<v[j].Y<<endl;
suma += v[j].Y - (*s.begin());
s.erase(s.begin());
s.insert(v[j].Y);
}
//cout << suma - (v[j].X - v[i].X) * 2LL << endl;
reza = max(reza, suma - (v[j].X - v[i].X) * 2LL);
}
}
printf("%lld\n", reza);
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... |