Submission #1307169

#TimeUsernameProblemLanguageResultExecution timeMemory
1307169chithanhnguyenFeast (NOI19_feast)C++20
0 / 100
1 ms576 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ld long double #define pii pair<int, int> #define fi first #define se second #define __builtin_popcount __builtin_popcountll #define all(x) (x).begin(), (x).end() #define BIT(x, i) (((x) >> (i)) & 1) #define MASK(x) ((1ll << (x))) #define debug(a, l, r) for (int _i = (l); _i <= (r); ++_i) cout << (a)[_i] << ' '; cout << '\n'; const int MAXN = 2005; const int INF = 1e18 + 7; int n, k, a[MAXN], pref[MAXN], dp[MAXN][MAXN]; signed main() { #ifdef NCTHANH freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } for (int i = 0; i <= n; ++i) for (int j = 0; j <= k; ++j) dp[i][j] = -INF; for (int i = 0; i <= n; ++i) dp[i][0] = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= min(i, k); ++j) { dp[i][j] = dp[i - 1][j]; for (int pre = i; pre >= j; --pre) { if (dp[pre - 1][j - 1] != -INF) dp[i][j] = max(dp[i][j], dp[pre - 1][j - 1] + (pref[i] - pref[pre - 1])); } } } cout << dp[n][k]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...