This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//bit chass 1
#include <bits/stdc++.h>
#define x first
#define y second
#define el "\n"
#define ll long long
#define pb push_back
#define pll pair <ll, ll>
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define lcm(x,y) x * y / __gcd(x, y)
#define ibase ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
const int N = 1e3 + 5, inf = 1e9 + 7, M = 2e6, MM = 2e6 + 5, K = 300;
const ll MI = 2e18, mm = 1e15;
const double P = 3.14;
ll a[N];
ll d[N][N];
void solve() {
int n, l = 1;
cin >> n;
for (int i = 0; i <= 1000; i++)
for (int j = 0; j <= 1000; j++)
d[i][j] = mm;
for (int i = 1; i <= n; i++)
cin >> a[i], a[i] += a[i - 1];
d[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
for (int k = 0; k <= l; k++) {
if (d[j][k] != mm && d[j][k] <= a[i] - a[j])
d[i][k + 1] = min(d[i][k + 1], a[i] - a[j]), l = max(l, k + 1);
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
if (d[i][j] != mm)
ans = max(ans, j);
}
cout << ans;
}
int main() {
ibase;
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
// cout << "Case " << i << ": ";
solve();
cout << el;
}
}
# | 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... |