Submission #1207649

#TimeUsernameProblemLanguageResultExecution timeMemory
1207649AmadooFeast (NOI19_feast)C++20
41 / 100
26 ms30860 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "local_debug.cpp" #else #define debug(...) #define debugArr(...) #endif #define int long long #define nl '\n' #define sp ' ' #define F first #define S second #define SZ(s) (int)((s).size()) const int N = 2e3 + 5; int a[N], dp[N][N], pre[N]; void solve() { int n, k; cin >> n >> k; for(int i = 1; i <= n; ++i) cin >> a[i]; for(int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + a[i]; for(int j = 1; j <= k; ++j) { int best = -1e12; for(int i = n; i >= 1; --i) { dp[i][j] = dp[i + 1][j]; best = max(best, dp[i + 1][j - 1] + pre[i]); dp[i][j] = max(dp[i][j], best - pre[i - 1]); } } cout << dp[1][k] << nl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int tc = 1; // cin >> tc; while(tc--) solve(); }
#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...