# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
960541 | Trisanu_Das | Cake 3 (JOI19_cake3) | C++17 | 4043 ms | 9744 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[j].ss);
val += a[j].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... |