Submission #791446

#TimeUsernameProblemLanguageResultExecution timeMemory
791446cheat_when_I_was_youngFeast (NOI19_feast)C++17
43 / 100
1091 ms16008 KiB
// #cheat_when_we_are_young // #cheatkhitacontre #khionhatoicheat // #thaycuckythatvong #include<bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define int long long using namespace std; const int NM = 2005, MN = 3e5 + 5; int n, k, a[MN], dp[NM][NM]; void sub1() { for (int i = 1; i <= n; ++i) a[i] += a[i-1]; cout << a[n]; } void sub2() { } void sub3() { int minprefix = 0, ans = 0; for (int i = 1; i <= n; ++i) { a[i] += a[i-1]; minprefix = min(minprefix, a[i]); ans = max(ans, a[i] - minprefix); } cout << ans; } void nnk() { for (int i = 1; i <= n; ++i) a[i] += a[i-1]; for (int i = 1; i <= n; ++i) for (int j = 1; j <= k; ++j) { dp[i][j] = max(dp[i][j], dp[i-1][j]); for (int p = 0; p < i; ++p) dp[i][j] = max(dp[i][j], dp[p][j-1] + a[i] - a[p]); } cout << dp[n][k]; } signed main() { IOS; cin >> n >> k; int check = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (a[i] < 0) ++check; } if (check == 0) { sub1(); return 0; } if (check == 1) { sub2(); return 0; } if (k == 1) { sub3(); return 0; } nnk(); }
#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...