Submission #173501

#TimeUsernameProblemLanguageResultExecution timeMemory
173501a1_NBigger segments (IZhO19_segments)C++14
37 / 100
1561 ms2576 KiB
#include <bits/stdc++.h>

#define F first
#define S second

using namespace std;

const int N = (int)5e5 + 5;

int n,a[N];

long long pref[N];

pair<int,long long> dp[N];
                  	
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
    	cin >> a[i];
    	pref[i] = pref[i - 1] + a[i];
    }
    dp[1] = {1,a[1]}; 
    for(int i = 2; i <= n; i++){
    	dp[i] = {dp[i - 1].F,pref[i]};
    	for(int j = 1; j < i; j++){
    		if(pref[i] - pref[j] >= dp[j].S && dp[i].F <= dp[j].F + 1){
    			dp[i].F = dp[j].F + 1;
    			dp[i].S = pref[i] - pref[j];
    		}
    	} 	
    }
    cout << dp[n].F;
	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...