Submission #539020

#TimeUsernameProblemLanguageResultExecution timeMemory
539020_karan_gandhiFeast (NOI19_feast)C++17
18 / 100
127 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() #define endl '\n' #define pl(var) " [" << #var << ": " << (var) << "] " #define ll long long void solve() { // dp[i][j] = the max sum that can be obtained if j subsegments are chosen and last subsegment ends at i // dp[i][j] = dp[0..i][j-1] int n, k; cin >> n >> k; vector<ll int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } vector<vector<ll int>> dp(n + 1, vector<ll int>(k + 1)); ll int ans = 0; ll int mn = 0; ll int pref = 0; for (int i = 0; i < n; i++) { pref += arr[i]; mn = min(pref, mn); dp[i][1] = max(pref - mn, pref); ans = max(ans, dp[i][1]); } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T = 1; // cin >> T; while (T--) 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...