이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
long long mx = 0;
for (int i = 0; i < n; i++) {
vector<long long> new_dp(m + 1);
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... |