#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5;
int a[1 + N];
ll sum[1 + N];
pair <int, ll> dp[1 + N];
vector <pair <ll, int>> s[1 + N];
#define pb push_back
int main () {
ios::sync_with_stdio (false);
cin.tie (0); cout.tie (0);
int 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++) {
int l = 1, r = i;
int best = 0;
while (l <= r) {
int mid = (l + r) / 2;
bool ok = false;
if (s[mid].size ()) {
auto x = s[mid][0];
if (x.first <= sum[i] - sum[x.second])
ok = true;
}
if (ok)
l = mid + 1, best = mid;
else
r = mid - 1;
}
if (best == 0) {
dp[i] = {1, sum[i]};
}
else {
l = 0, r = s[best].size () - 1;
ll this_sum = 0;
while (l <= r) {
int mid = (l + r) / 2;
auto x = s[best][mid];
if (x.first <= sum[i] - sum[x.second]) {
l = mid + 1;
this_sum = sum[i] - sum[x.second];
}
else
r = mid - 1;
}
dp[i] = {best + 1, this_sum};
}
s[dp[i].first].pb ({dp[i].second, i});
}
cout << dp[n].first << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12024 KB |
Output is correct |
3 |
Correct |
12 ms |
12024 KB |
Output is correct |
4 |
Correct |
13 ms |
12152 KB |
Output is correct |
5 |
Correct |
12 ms |
12152 KB |
Output is correct |
6 |
Correct |
13 ms |
12152 KB |
Output is correct |
7 |
Correct |
13 ms |
12152 KB |
Output is correct |
8 |
Correct |
13 ms |
12156 KB |
Output is correct |
9 |
Correct |
15 ms |
12152 KB |
Output is correct |
10 |
Correct |
12 ms |
12024 KB |
Output is correct |
11 |
Correct |
13 ms |
12024 KB |
Output is correct |
12 |
Correct |
12 ms |
12024 KB |
Output is correct |
13 |
Correct |
12 ms |
12024 KB |
Output is correct |
14 |
Correct |
13 ms |
12024 KB |
Output is correct |
15 |
Correct |
12 ms |
12044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12024 KB |
Output is correct |
3 |
Correct |
12 ms |
12024 KB |
Output is correct |
4 |
Correct |
13 ms |
12152 KB |
Output is correct |
5 |
Correct |
12 ms |
12152 KB |
Output is correct |
6 |
Correct |
13 ms |
12152 KB |
Output is correct |
7 |
Correct |
13 ms |
12152 KB |
Output is correct |
8 |
Correct |
13 ms |
12156 KB |
Output is correct |
9 |
Correct |
15 ms |
12152 KB |
Output is correct |
10 |
Correct |
12 ms |
12024 KB |
Output is correct |
11 |
Correct |
13 ms |
12024 KB |
Output is correct |
12 |
Correct |
12 ms |
12024 KB |
Output is correct |
13 |
Correct |
12 ms |
12024 KB |
Output is correct |
14 |
Correct |
13 ms |
12024 KB |
Output is correct |
15 |
Correct |
12 ms |
12044 KB |
Output is correct |
16 |
Correct |
12 ms |
12152 KB |
Output is correct |
17 |
Correct |
13 ms |
12152 KB |
Output is correct |
18 |
Incorrect |
13 ms |
12152 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12024 KB |
Output is correct |
3 |
Correct |
12 ms |
12024 KB |
Output is correct |
4 |
Correct |
13 ms |
12152 KB |
Output is correct |
5 |
Correct |
12 ms |
12152 KB |
Output is correct |
6 |
Correct |
13 ms |
12152 KB |
Output is correct |
7 |
Correct |
13 ms |
12152 KB |
Output is correct |
8 |
Correct |
13 ms |
12156 KB |
Output is correct |
9 |
Correct |
15 ms |
12152 KB |
Output is correct |
10 |
Correct |
12 ms |
12024 KB |
Output is correct |
11 |
Correct |
13 ms |
12024 KB |
Output is correct |
12 |
Correct |
12 ms |
12024 KB |
Output is correct |
13 |
Correct |
12 ms |
12024 KB |
Output is correct |
14 |
Correct |
13 ms |
12024 KB |
Output is correct |
15 |
Correct |
12 ms |
12044 KB |
Output is correct |
16 |
Correct |
12 ms |
12152 KB |
Output is correct |
17 |
Correct |
13 ms |
12152 KB |
Output is correct |
18 |
Incorrect |
13 ms |
12152 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12024 KB |
Output is correct |
3 |
Correct |
12 ms |
12024 KB |
Output is correct |
4 |
Correct |
13 ms |
12152 KB |
Output is correct |
5 |
Correct |
12 ms |
12152 KB |
Output is correct |
6 |
Correct |
13 ms |
12152 KB |
Output is correct |
7 |
Correct |
13 ms |
12152 KB |
Output is correct |
8 |
Correct |
13 ms |
12156 KB |
Output is correct |
9 |
Correct |
15 ms |
12152 KB |
Output is correct |
10 |
Correct |
12 ms |
12024 KB |
Output is correct |
11 |
Correct |
13 ms |
12024 KB |
Output is correct |
12 |
Correct |
12 ms |
12024 KB |
Output is correct |
13 |
Correct |
12 ms |
12024 KB |
Output is correct |
14 |
Correct |
13 ms |
12024 KB |
Output is correct |
15 |
Correct |
12 ms |
12044 KB |
Output is correct |
16 |
Correct |
12 ms |
12152 KB |
Output is correct |
17 |
Correct |
13 ms |
12152 KB |
Output is correct |
18 |
Incorrect |
13 ms |
12152 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12024 KB |
Output is correct |
2 |
Correct |
13 ms |
12024 KB |
Output is correct |
3 |
Correct |
12 ms |
12024 KB |
Output is correct |
4 |
Correct |
13 ms |
12152 KB |
Output is correct |
5 |
Correct |
12 ms |
12152 KB |
Output is correct |
6 |
Correct |
13 ms |
12152 KB |
Output is correct |
7 |
Correct |
13 ms |
12152 KB |
Output is correct |
8 |
Correct |
13 ms |
12156 KB |
Output is correct |
9 |
Correct |
15 ms |
12152 KB |
Output is correct |
10 |
Correct |
12 ms |
12024 KB |
Output is correct |
11 |
Correct |
13 ms |
12024 KB |
Output is correct |
12 |
Correct |
12 ms |
12024 KB |
Output is correct |
13 |
Correct |
12 ms |
12024 KB |
Output is correct |
14 |
Correct |
13 ms |
12024 KB |
Output is correct |
15 |
Correct |
12 ms |
12044 KB |
Output is correct |
16 |
Correct |
12 ms |
12152 KB |
Output is correct |
17 |
Correct |
13 ms |
12152 KB |
Output is correct |
18 |
Incorrect |
13 ms |
12152 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |