제출 #819329

#제출 시각아이디문제언어결과실행 시간메모리
819329LucaIlieCake 3 (JOI19_cake3)C++17
0 / 100
1 ms724 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...