# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
113722 | Mamnoon_Siam | Cake 3 (JOI19_cake3) | C++17 | 4011 ms | 460 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;
using ii = pair<int, int>;
using ll = long long;
const int maxn = 2e5 + 5;
int n, m;
int v[maxn], c[maxn];
int main(int argc, char const *argv[])
{
// freopen("in", "r", stdin);
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> v[i] >> c[i];
}
{
vector<ii> tmp(n);
for(int i = 0; i < n; i++) {
tmp[i] = ii(c[i + 1], v[i + 1]);
}
sort(tmp.begin(), tmp.end());
for(int i = 0; i < n; i++) {
v[i + 1] = tmp[i].second;
c[i + 1] = tmp[i].first;
}
}
ll ans = LLONG_MIN;
int last = 1;
for(int i = 1; i + m - 1 <= n; i++) {
priority_queue<ll> Q;
int opt = -1;
ll mn = LLONG_MIN;
for(int j = i; j <= n; j++) {
Q.push(v[j]);
if(Q.size() >= m) {
ll S = 0;
vector<ll> tmp;
while(tmp.size() < m) {
S += Q.top();
tmp.emplace_back(Q.top());
Q.pop();
}
while(tmp.size()) {
Q.push(tmp.back());
tmp.pop_back();
}
S -= 2 * (c[j] - c[i]);
if(mn < S) {
mn = S;
opt = j;
}
}
}
ans = max(ans, mn);
assert(last <= opt);
last = opt;
}
cout << ans << endl;
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... |