제출 #1294852

#제출 시각아이디문제언어결과실행 시간메모리
1294852azamuraiBigger segments (IZhO19_segments)C++20
13 / 100
13 ms4440 KiB
#include <bits/stdc++.h>

#define int long long
#define ll long long
#define mp make_pair
#define fi first 
#define se second 
#define Sz(x) (int)x.size()

using namespace std;

const int N = 3005;
const int inf = INT_MAX;
int n, a[N], dp[N][N], pref[N];

void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		pref[i] = pref[i - 1] + a[i];
	}	
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			dp[i][j] = 0;
		}
	}
	for (int i = 1; i <= n; i++) {
		dp[i][0] = 1;
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j < i; j++) {
			for (int k = j - 1; k >= max(0ll, j - 50); k--) {
				int sum1 = (pref[i] - pref[j]);
				int sum2 = (pref[j] - pref[k]);
				if (sum1 >= sum2 && dp[j][k] != 0) {
					dp[i][j] = max(dp[i][j], dp[j][k] + 1);
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, dp[n][i]);
	}
	cout << ans;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << '\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...