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;
struct ab {
long long a, b;
};
const int MAX_N = 5000;
ab v[MAX_N];
long long dp[MAX_N][MAX_N];
int main() {
int n, m;
cin >> n >> m;
for ( int i = 1; i <= n; i++ )
cin >> v[i].a >> v[i].b;
sort( v + 1, v + 1 + n, []( ab x, ab y ) {
return x.b < y.b;
} );
for ( int i = 1; i <= n; i++ ) {
dp[i][1] = v[i].a;
for ( int k = 1; k <= m; k++ ) {
for ( int j = 1; j < i; j++ )
dp[i][k] = max( dp[i][k], dp[j][k - 1] + v[i].a - 2 * (v[i].b - v[j].b) );
}
}
long long ans = 0;
for ( int i = 1; i <= n; i++ )
ans = max( ans, dp[i][m] );
cout << 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... |