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
using namespace std;
typedef pair<int,int> ii;
main(){
int n,m;
cin >> n >> m;
ii arr[n];
for (int i = 0; i < n; i++) cin >> arr[i].second >> arr[i].first;
sort(arr,arr+n);
int ans = -1e18;
for (int i = 0; i+m <= n; i++){
int sum = 0;
priority_queue<int,vector<int>,greater<int> > pq;
for (int j = i; j < i+m; j++){
pq.push(arr[j].second);
sum += arr[j].second;
}
ans = max(ans,sum-2*(arr[i+m-1].first-arr[i].first));
for (int j = i+m; j < n; j++){
int v = arr[j].second;
if (v > pq.top()){
sum += v-pq.top();
pq.pop();
pq.push(v);
ans = max(ans,sum-2*(arr[j].first-arr[i].first));
}
}
}
cout << ans;
}
Compilation message (stderr)
cake3.cpp:5:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |