Submission #819507

#TimeUsernameProblemLanguageResultExecution timeMemory
819507LucaIlieCake 3 (JOI19_cake3)C++17
5 / 100
4065 ms22476 KiB
#include <bits/stdc++.h> using namespace std; struct ab { int a, b; }; const int MAX_N = 5000; const long long INF = 1e18; 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][0] = -INF; dp[i][1] = v[i].a; for ( int k = 2; k <= m; k++ ) { dp[i][k] = -INF; 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 = -INF; for ( int i = 1; i <= n; i++ ) ans = max( ans, dp[i][m] ); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...