#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return uniform_int_distribution <int> (l, r) (rnd);
}
const int inf = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector <int> a(n + 1, 0);
vector <ll> pref(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
pref[i] = a[i] + pref[i - 1];
}
vector <pair <int, ll> > dp(n + 1, {0, inf});
dp[0] = {0, 0};
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
ll sum = pref[i] - pref[j];
if (sum >= dp[j].second) {
if (dp[j].first + 1 > dp[i].first) {
dp[i].first = dp[j].first + 1;
dp[i].second = sum;
} else if (dp[j].first + 1 == dp[i].first) {
dp[i].second = min(dp[i].second, sum);
}
}
}
}
for (int i = 1; i <= n; i++) {
if (dp[i].first < dp[i - 1].first) {
assert(0);
}
}
cout << dp[n].first << '\n';
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int test_cnt = 1;
cin >> test_cnt;
while (test_cnt--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |