This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int dp[501][501];
int main(){
	int n;
	cin>>n;
	vi arr(n);
	for(int i = 0; i < n; i++)	cin>>arr[i];
	
	int pref[n];
	pref[0] = arr[0];
	for(int i = 1; i < n; i++)	pref[i] = pref[i-1]+arr[i];
	memset(dp, 0, sizeof dp);
	dp[0][0]= 1;
	for(int i = 1; i < n; i++){
		for(int j = i; j >= 0; j--){
			if(j==0)
				dp[i][j] = 1;
			else{
				for(int k = j - 1; k >= 0; k--){
					ll r = pref[i] - pref[j-1];
					ll l = pref[j-1];
					if(k)	l -= pref[k-1];	
					if(l <= r){
						dp[i][j] = max(dp[i][j], dp[j-1][k] + 1);
					}
				}
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++)	ans = max(ans, dp[n-1][i]);
	cout<<ans<<endl;
	return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |