Submission #961444

#TimeUsernameProblemLanguageResultExecution timeMemory
961444ByeWorldCigle (COI21_cigle)C++14
9 / 100
70 ms3420 KiB
#include <bits/stdc++.h>
#include <random>
#define ll long long
#define int long long
#define fi first
#define se second
#define pb push_back
#define md ((l+r)>>1)
#define lf (id<<1)
#define rg ((id<<1)|1)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,pii> ipii;
const int MAXN = 5e3+10;
const int MAXA = 1e6+10;
const int INF = 2e9+10;
const int LOG = 30;
const int MOD = 1e9+7;
void chmx(int &a, int b){
	a = max(a, b);
}

int n;
int a[MAXN], pr[MAXN], dp[MAXN][MAXN];

signed main() {
	// ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		pr[i] = pr[i-1] + a[i];
	}
	for(int r=1; r<=n; r++){
		for(int l=1; l<=r; l++){
			// build dp[l][r], row atas

			int down = 0, idx = l, add = 0;
			for(int k=l-1; k>=1; k--){
				// cek dp[k][l], row bawah
				chmx(dp[l][r], dp[k][l-1]+add);

				down += a[k];
				while(idx+1<=r-1 && pr[idx]-pr[l-1] < down){ // r gk boleh dipake
					// atas masi kurang
					idx++;
				} 
				if(pr[idx]-pr[l-1] == down) add++; // kena 4
			}
		}
	}

	int ANS = 0;
	for(int i=1; i<=n; i++) ANS = max(ANS, dp[i][n]);
	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...