Submission #1002762

#TimeUsernameProblemLanguageResultExecution timeMemory
1002762SofiatpcCigle (COI21_cigle)C++14
48 / 100
11 ms1884 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define sc second const int MAXN = 505; int dp[MAXN][MAXN], d[MAXN], sp[MAXN]; int sum(int i, int j){ return sp[j] - sp[i-1]; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; for(int i = 1; i <= n; i++){ cin>>d[i]; sp[i] = sp[i-1]+d[i]; } int ans = 0; for(int r = n-1; r >= 1; r--){ set<pair<int,int>> st; for(int j = r+1; j < n; j++)st.insert({sum(r+1,j), dp[r+1][j+1]}); int qtd = 0; for(int l = r; l >= 1; l--){ dp[l][r] = max(dp[l+1][r], dp[l][r+1]); if(l!=r){ auto it = st.lower_bound({sum(l+1,r),0}); if(it == st.end() || it->fi > sum(l+1,r))continue; qtd++; dp[l][r] = max(dp[l][r], (it->sc) + qtd); } ans = max(ans,dp[l][r]); } } cout<<ans<<"\n"; }
#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...