# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334202 | BeanZ | Bigger segments (IZhO19_segments) | C++14 | 90 ms | 71020 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 3e3 + 5;
long long mod = 1e9 + 7;
const int lim = 5e5;
const int lg = 20;
const int base = 311;
const long double eps = 1e-6;
ll a[N], sum[N], dp[N][N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("test.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], sum[i] = sum[i - 1] + a[i];
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
dp[i][j] = -1e9;
}
}
for (int i = 1; i <= n; i++) dp[1][i] = 1;
for (int i = 2; i <= n; i++){
ll best = -1e9;
ll l = i - 1;
for (int j = i; j <= n; j++){
ll tot = sum[j] - sum[i - 1];
while (l > 0 && (sum[i - 1] - sum[l - 1]) <= tot){
best = max(best, dp[l][i - 1]);
l--;
}
dp[i][j] = best + 1;
}
}
//cout << dp[1][1] << " " << dp[2][3] << endl;
ll ans = 0;
for (int i = 1; i <= n; i++){
ans = max(ans, dp[i][n]);
}
cout << ans;
}
/*
Ans:
Out:
*/
Compilation message (stderr)
# | 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... |