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());
vector<long long> dp(m + 1, -1e18);
long long mx = -1e18;
for (int i = 0; i < n; i++) {
vector<long long> new_dp(m + 1, -1e18);
new_dp[1] = a[i].second + 2 * a[i].first;
for (int j = 2; j < m; j++) {
new_dp[j] = dp[j - 1] + a[i].second;
}
if (i >= m - 1) mx = max(mx, dp[m - 1] + a[i].second - 2 * a[i].first);
for (int j = 1; j < m; j++) dp[j] = max(dp[j], new_dp[j]);
}
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... |