Submission #497714

#TimeUsernameProblemLanguageResultExecution timeMemory
497714IerusBigger segments (IZhO19_segments)C++17
37 / 100
1581 ms3404 KiB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define int long long
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
const int E = 5e5+777;
const long long inf = 1e18+777;
const int N = 3e3+777;
const int MOD = 1e9+7;
int n, a[E], pref[E];
pair<int,int> dp[E];
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];
    	pref[i] = pref[i-1] + a[i];
	}
	for(int i = 1; i <= n; ++i){
		dp[i] = {0, 1};
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j <= i; ++j){                
			if(pref[i] - pref[j] >= pref[j] - pref[dp[j].S]){
				dp[i] = max(dp[i], {dp[j].first+1, j});
			}
		}
	}
//	for(int i = 1; i <= n; ++i){
//		cerr << i << " -> " << dp[i].first << ' ' << dp[i].second << '\n';
//	}
	cout << dp[n].F;
}







#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...