Submission #482022

#TimeUsernameProblemLanguageResultExecution timeMemory
482022ak2006Bigger segments (IZhO19_segments)C++14
0 / 100
1 ms204 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using pii = pair<int,int>; using pll = pair<ll,ll>; using vpii = vector<pii>; using vpll = vector<pll>; const ll mod = 1e9 + 7,inf = 1e18; #define pb push_back #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); void setIO() { fast; } int main() { setIO(); int n; cin>>n; vl a(n + 1),p(n + 1); vpll dp(n + 1);//dp[i] stores {maxSegmentLength, -minSumOfLastSegment} for (int i = 1;i<=n;i++){cin>>a[i];p[i] = p[i - 1] + a[i];} for (int i = 1;i<=n;i++){ dp[i] = {1,-p[1]}; for (int j = i - 1;j>=1;j--){ ll currentLast = p[i] - p[j]; if (currentLast >= -dp[j].second) dp[i] = max(dp[i],{dp[j].first + 1,-currentLast}); } } cout<<dp[n].first; 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...