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>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
const int MN = 2005;
int n, m, dp[MN][MN];
pii a[MN];
int32_t main() {
boost();
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i].s >> a[i].f, a[i].f *= 2;
sort(a + 1, a + n + 1);
int ans = -0x3f3f3f3f;
memset(dp, -0x3f, sizeof(dp));
for (int i = 1; i <= n; i++) {
dp[i][1] = a[i].s;
for (int j = 2; j <= m; j++) {
for (int p = 1; p < i; p++) dp[i][j] = max(dp[i][j], dp[p][j - 1] + a[i].s - a[i].f + a[p].f);
}
ans = max(ans, dp[i][m]);
}
printf("%lld\n", ans);
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... |