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>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
void testCase() {
int n, m;
cin >> n >> m;
vector<pair<long long, long long>> a(n);
for (auto &[x, y] : a) cin >> y >> x;
sort(a.begin(), a.end());
long long mx = 0;
for (int i = m - 1; i < n; i++) {
for (int j = 0; j <= i - m + 1; j++) {
vector<long long> v;
for (int k = j; k <= i; k++) v.push_back(a[k].second);
sort(v.rbegin(), v.rend());
long long ans = 0;
for (int k = 0; k < m; k++) ans += v[k];
ans -= 2 * (a[i].first - a[j].first);
mx = max(mx, ans);
}
}
cout << mx << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
testCase();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |