Submission #1116439

#TimeUsernameProblemLanguageResultExecution timeMemory
1116439KK_1729Bigger segments (IZhO19_segments)C++17
37 / 100
1561 ms3152 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define pb push_back #define all(a) a.begin(), a.end() #define endl "\n" void printVector(vector<int> a){ for (auto x: a) cout << x << " "; cout << endl; } void solve(){ int n; cin >> n; vector<int> a(n); FOR(i,0,n) cin >> a[i]; vector<pair<int, int>> dp(n); // dp[i] denotes the maximum number of segments possible and the minimum value of previous segment dp[0] = {1, a[0]}; FOR(i,1,n){ dp[i] = {dp[i-1].first, dp[i-1].second+a[i]}; int o = a[i]; for (int j = i-1; j >= 0; j--){ if (o >= dp[j].second){ if (dp[j].first+1 > dp[i].first){ dp[i].first = dp[j].first+1; dp[i].second = o; }else if (dp[j].first+1 == dp[i].first){ dp[i].second = min(dp[i].second, o); } } o += a[j]; } } cout << dp[n-1].first << endl; } int32_t 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...