Submission #997619

#TimeUsernameProblemLanguageResultExecution timeMemory
997619LuvidiBigger segments (IZhO19_segments)C++17
27 / 100
1524 ms71008 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define fs first #define sc second #define pb push_back void solve() { int n; cin>>n; ll a[n+1],pre[n+1]; pre[0]=0; for(int i=0;i<n;i++){ cin>>a[i+1]; pre[i+1]=pre[i]+a[i+1]; } ll dp[n+1][n+1]; int idx[n+1]; for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++){ dp[i][j]=1e18; } idx[i]=1e9; } dp[0][0]=0; idx[0]=0; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(idx[j-1]>=i)continue; for(int x=1;x<=i-idx[j-1];x++){ if(pre[i]-pre[i-x]>=dp[i-x][j-1]){ dp[i][j]=min(dp[i][j],pre[i]-pre[i-x]); idx[j]=min(idx[j],i); } } } } ll ans=0; for(int i=1;i<=n;i++){ if(dp[n][i]<1e18)ans=i; } cout<<ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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...