# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
982533 | Jarif_Rahman | 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>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
vector<pair<ll, ll>> cv(n);
for(auto &[c, v]: cv) cin >> v >> c;
sort(cv.begin(), cv.end());
ll ans = -1e18;
for(int i = 0; i < n; i++){
ll sum = 0;
priority_queue<ll> pq;
for(int j = i; j < n; j++){
if(pq.size() < m) sum+=cv[j].second, pq.push(-cv[j].second);
else if(cv[j].second > -pq.top()){
sum+=pq.top();
sum+=cv[j].second;
pq.push(-cv[j].second);
}
if(j-i+1 >= m) ans = max(ans, sum-(cv[j].first-cv[i].first)*2);
}
}
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... |