# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
960540 | Trisanu_Das | 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;
#define int long long
#define ff first
#define ss second
signed main(){
int n, m; cin >> n >> m;
pair<int, int> a[n];
for(int i = 0; i < n; i++) cin >> a[i].ss >> a[i].ff;
sort(a, a + n);
int ans = LLONG_MIN;
for(int i = 0; i < n; i++){
multiset<int> s;
int val = 0;
for(int j = i; j < n; j++){
s.insert(a[i].ss);
val += a[i].ss;
if(s.size() > m){
val -= *s.begin();
s.erase(s.begin());
}
if(s.size() == m) ans = max(ans, val - 2 * (a[j].ff - a[i].ff));
}
}
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... |