# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376792 | casperwang | Cake 3 (JOI19_cake3) | C++14 | 1 ms | 384 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>
#define int long long
#define All(x) x.begin(), x.end()
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 200000;
int N, M;
pii arr[MAXN+1];
int ans;
void solve() {
priority_queue <int, vector<int>, greater<int>> val;
for (int i = 1; i <= N; i++) {
int sum = arr[i].ff + arr[i].ss * 2;
for (int j = i+1; j <= N; j++) {
sum += arr[j].ff;
val.push(arr[j].ff);
if (val.size() + 1 > M) {
sum -= val.top();
val.pop();
}
if (val.size() == M-1)
ans = max(ans, sum - 2 * arr[j].ss);
}
while (val.size()) val.pop();
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> M;
for (int i = 1; i <= N; i++) {
auto &[v, c] = arr[i];
cin >> v >> c;
}
sort(arr+1, arr+1+N, [](const pii a, const pii b) {
return a.ss < b.ss;
});
solve();
cout << ans << '\n';
}
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... |