제출 #837960

#제출 시각아이디문제언어결과실행 시간메모리
837960MODDIBigger segments (IZhO19_segments)C++14
27 / 100
85 ms4556 KiB
#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;
ll dp[511][511];
int main(){
	int n;
	cin>>n;
	vl arr(n+1);
	for(int i = 1; i <= n; i++)	cin>>arr[i];
	
	ll pref[n+1];
	for(int i = 1; i <= n; i++)	pref[i] = pref[i-1] + arr[i];
	memset(dp, 0x3f, sizeof dp);
	dp[0][0] = 0;
	for(int i = 1; i <= 	n; i++){
		for(int j = 1; j <= i; j++){
			for(int k = i; k >= 1; k--){
				ll sum = pref[i] - pref[k-1];
				if(sum >= dp[k-1][j-1]){
					dp[i][j] = min(dp[i][j], sum);
				}
			}
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(dp[n][i] < 1e18 + 5)	ans = max(ans, i);
	}
	cout<<ans<<endl;
	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...