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 <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define int long long
struct Perle {
int t, c;
bool operator<(const Perle& other) {
return t < other.t;
}
};
int N, M;
vector<Perle> perles;
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> N >> M;
perles.resize(N);
for (int i = 0; i < N; i++) {
cin >> perles[i].c >> perles[i].t;
}
sort(perles.begin(), perles.end());
int ans = -1e18;
for (int deb = 0; deb < N; deb++) {
int sum = 0;
priority_queue<int,vector<int>,greater<int>> pq;
for (int fin = deb; fin < N; fin++) {
if (fin > deb+M-1) {
sum -= pq.top();
pq.pop();
}
pq.push(perles[fin].c);
sum += perles[fin].c;
if (fin >= deb+M-1) {
ans = max(ans, sum-2*abs(perles[deb].t-perles[fin].t));
}
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |