#include <bits/stdc++.h>
using namespace std;
void just_do_it();
int main() {
#ifdef KAMIRULEZ
freopen("kamirulez.inp", "r", stdin);
freopen("kamirulez.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
just_do_it();
return 0;
}
const int maxn = 5e5 + 20;
int a[maxn];
long long pref[maxn];
long long mi[maxn];
int dp[maxn];
vector<int> q[maxn];
bool cmp(long long val, int i) {
return val < pref[i] + mi[i];
}
void just_do_it() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
q[0].push_back(0);
int res = 0;
for (int i = 1; i <= n; i++) {
if (pref[q[res][0]] + mi[q[res][0]] <= pref[i]) {
res++;
}
int j = *prev(upper_bound(q[res - 1].begin(), q[res - 1].end(), pref[i], cmp));
mi[i] = pref[i] - pref[j];
while (!q[res].empty() && pref[q[res].back()] + mi[q[res].back()] >= pref[i] + mi[i]) {
q[res].pop_back();
}
q[res].push_back(i);
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14964 KB |
Output is correct |
4 |
Correct |
3 ms |
14940 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14940 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14936 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
3 ms |
14936 KB |
Output is correct |
11 |
Correct |
3 ms |
15024 KB |
Output is correct |
12 |
Correct |
3 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14940 KB |
Output is correct |
14 |
Correct |
3 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14964 KB |
Output is correct |
4 |
Correct |
3 ms |
14940 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14940 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14936 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
3 ms |
14936 KB |
Output is correct |
11 |
Correct |
3 ms |
15024 KB |
Output is correct |
12 |
Correct |
3 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14940 KB |
Output is correct |
14 |
Correct |
3 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14960 KB |
Output is correct |
16 |
Correct |
3 ms |
14940 KB |
Output is correct |
17 |
Correct |
3 ms |
14936 KB |
Output is correct |
18 |
Correct |
3 ms |
14940 KB |
Output is correct |
19 |
Correct |
3 ms |
14968 KB |
Output is correct |
20 |
Correct |
3 ms |
14940 KB |
Output is correct |
21 |
Correct |
3 ms |
14940 KB |
Output is correct |
22 |
Correct |
3 ms |
14940 KB |
Output is correct |
23 |
Correct |
4 ms |
14940 KB |
Output is correct |
24 |
Correct |
3 ms |
15192 KB |
Output is correct |
25 |
Correct |
3 ms |
14936 KB |
Output is correct |
26 |
Correct |
3 ms |
14936 KB |
Output is correct |
27 |
Correct |
3 ms |
14940 KB |
Output is correct |
28 |
Correct |
3 ms |
14940 KB |
Output is correct |
29 |
Correct |
3 ms |
14940 KB |
Output is correct |
30 |
Correct |
3 ms |
14940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14964 KB |
Output is correct |
4 |
Correct |
3 ms |
14940 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14940 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14936 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
3 ms |
14936 KB |
Output is correct |
11 |
Correct |
3 ms |
15024 KB |
Output is correct |
12 |
Correct |
3 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14940 KB |
Output is correct |
14 |
Correct |
3 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14960 KB |
Output is correct |
16 |
Correct |
3 ms |
14940 KB |
Output is correct |
17 |
Correct |
3 ms |
14936 KB |
Output is correct |
18 |
Correct |
3 ms |
14940 KB |
Output is correct |
19 |
Correct |
3 ms |
14968 KB |
Output is correct |
20 |
Correct |
3 ms |
14940 KB |
Output is correct |
21 |
Correct |
3 ms |
14940 KB |
Output is correct |
22 |
Correct |
3 ms |
14940 KB |
Output is correct |
23 |
Correct |
4 ms |
14940 KB |
Output is correct |
24 |
Correct |
3 ms |
15192 KB |
Output is correct |
25 |
Correct |
3 ms |
14936 KB |
Output is correct |
26 |
Correct |
3 ms |
14936 KB |
Output is correct |
27 |
Correct |
3 ms |
14940 KB |
Output is correct |
28 |
Correct |
3 ms |
14940 KB |
Output is correct |
29 |
Correct |
3 ms |
14940 KB |
Output is correct |
30 |
Correct |
3 ms |
14940 KB |
Output is correct |
31 |
Correct |
3 ms |
14940 KB |
Output is correct |
32 |
Correct |
3 ms |
14940 KB |
Output is correct |
33 |
Correct |
3 ms |
14940 KB |
Output is correct |
34 |
Correct |
3 ms |
14940 KB |
Output is correct |
35 |
Correct |
3 ms |
14940 KB |
Output is correct |
36 |
Correct |
3 ms |
15012 KB |
Output is correct |
37 |
Correct |
3 ms |
14940 KB |
Output is correct |
38 |
Correct |
3 ms |
14940 KB |
Output is correct |
39 |
Correct |
3 ms |
14940 KB |
Output is correct |
40 |
Correct |
4 ms |
14940 KB |
Output is correct |
41 |
Correct |
3 ms |
14940 KB |
Output is correct |
42 |
Correct |
3 ms |
14940 KB |
Output is correct |
43 |
Correct |
4 ms |
14936 KB |
Output is correct |
44 |
Correct |
3 ms |
14940 KB |
Output is correct |
45 |
Correct |
3 ms |
14940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14964 KB |
Output is correct |
4 |
Correct |
3 ms |
14940 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14940 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14936 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
3 ms |
14936 KB |
Output is correct |
11 |
Correct |
3 ms |
15024 KB |
Output is correct |
12 |
Correct |
3 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14940 KB |
Output is correct |
14 |
Correct |
3 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14960 KB |
Output is correct |
16 |
Correct |
3 ms |
14940 KB |
Output is correct |
17 |
Correct |
3 ms |
14936 KB |
Output is correct |
18 |
Correct |
3 ms |
14940 KB |
Output is correct |
19 |
Correct |
3 ms |
14968 KB |
Output is correct |
20 |
Correct |
3 ms |
14940 KB |
Output is correct |
21 |
Correct |
3 ms |
14940 KB |
Output is correct |
22 |
Correct |
3 ms |
14940 KB |
Output is correct |
23 |
Correct |
4 ms |
14940 KB |
Output is correct |
24 |
Correct |
3 ms |
15192 KB |
Output is correct |
25 |
Correct |
3 ms |
14936 KB |
Output is correct |
26 |
Correct |
3 ms |
14936 KB |
Output is correct |
27 |
Correct |
3 ms |
14940 KB |
Output is correct |
28 |
Correct |
3 ms |
14940 KB |
Output is correct |
29 |
Correct |
3 ms |
14940 KB |
Output is correct |
30 |
Correct |
3 ms |
14940 KB |
Output is correct |
31 |
Correct |
3 ms |
14940 KB |
Output is correct |
32 |
Correct |
3 ms |
14940 KB |
Output is correct |
33 |
Correct |
3 ms |
14940 KB |
Output is correct |
34 |
Correct |
3 ms |
14940 KB |
Output is correct |
35 |
Correct |
3 ms |
14940 KB |
Output is correct |
36 |
Correct |
3 ms |
15012 KB |
Output is correct |
37 |
Correct |
3 ms |
14940 KB |
Output is correct |
38 |
Correct |
3 ms |
14940 KB |
Output is correct |
39 |
Correct |
3 ms |
14940 KB |
Output is correct |
40 |
Correct |
4 ms |
14940 KB |
Output is correct |
41 |
Correct |
3 ms |
14940 KB |
Output is correct |
42 |
Correct |
3 ms |
14940 KB |
Output is correct |
43 |
Correct |
4 ms |
14936 KB |
Output is correct |
44 |
Correct |
3 ms |
14940 KB |
Output is correct |
45 |
Correct |
3 ms |
14940 KB |
Output is correct |
46 |
Correct |
9 ms |
17116 KB |
Output is correct |
47 |
Correct |
13 ms |
17244 KB |
Output is correct |
48 |
Correct |
13 ms |
18012 KB |
Output is correct |
49 |
Correct |
14 ms |
19036 KB |
Output is correct |
50 |
Correct |
18 ms |
20828 KB |
Output is correct |
51 |
Correct |
17 ms |
17756 KB |
Output is correct |
52 |
Correct |
10 ms |
16476 KB |
Output is correct |
53 |
Correct |
6 ms |
15788 KB |
Output is correct |
54 |
Correct |
12 ms |
16988 KB |
Output is correct |
55 |
Correct |
14 ms |
18012 KB |
Output is correct |
56 |
Correct |
13 ms |
20192 KB |
Output is correct |
57 |
Correct |
11 ms |
18904 KB |
Output is correct |
58 |
Correct |
13 ms |
19036 KB |
Output is correct |
59 |
Correct |
14 ms |
20088 KB |
Output is correct |
60 |
Correct |
12 ms |
18524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14964 KB |
Output is correct |
4 |
Correct |
3 ms |
14940 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14940 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14936 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
3 ms |
14936 KB |
Output is correct |
11 |
Correct |
3 ms |
15024 KB |
Output is correct |
12 |
Correct |
3 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14940 KB |
Output is correct |
14 |
Correct |
3 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14960 KB |
Output is correct |
16 |
Correct |
3 ms |
14940 KB |
Output is correct |
17 |
Correct |
3 ms |
14936 KB |
Output is correct |
18 |
Correct |
3 ms |
14940 KB |
Output is correct |
19 |
Correct |
3 ms |
14968 KB |
Output is correct |
20 |
Correct |
3 ms |
14940 KB |
Output is correct |
21 |
Correct |
3 ms |
14940 KB |
Output is correct |
22 |
Correct |
3 ms |
14940 KB |
Output is correct |
23 |
Correct |
4 ms |
14940 KB |
Output is correct |
24 |
Correct |
3 ms |
15192 KB |
Output is correct |
25 |
Correct |
3 ms |
14936 KB |
Output is correct |
26 |
Correct |
3 ms |
14936 KB |
Output is correct |
27 |
Correct |
3 ms |
14940 KB |
Output is correct |
28 |
Correct |
3 ms |
14940 KB |
Output is correct |
29 |
Correct |
3 ms |
14940 KB |
Output is correct |
30 |
Correct |
3 ms |
14940 KB |
Output is correct |
31 |
Correct |
3 ms |
14940 KB |
Output is correct |
32 |
Correct |
3 ms |
14940 KB |
Output is correct |
33 |
Correct |
3 ms |
14940 KB |
Output is correct |
34 |
Correct |
3 ms |
14940 KB |
Output is correct |
35 |
Correct |
3 ms |
14940 KB |
Output is correct |
36 |
Correct |
3 ms |
15012 KB |
Output is correct |
37 |
Correct |
3 ms |
14940 KB |
Output is correct |
38 |
Correct |
3 ms |
14940 KB |
Output is correct |
39 |
Correct |
3 ms |
14940 KB |
Output is correct |
40 |
Correct |
4 ms |
14940 KB |
Output is correct |
41 |
Correct |
3 ms |
14940 KB |
Output is correct |
42 |
Correct |
3 ms |
14940 KB |
Output is correct |
43 |
Correct |
4 ms |
14936 KB |
Output is correct |
44 |
Correct |
3 ms |
14940 KB |
Output is correct |
45 |
Correct |
3 ms |
14940 KB |
Output is correct |
46 |
Correct |
9 ms |
17116 KB |
Output is correct |
47 |
Correct |
13 ms |
17244 KB |
Output is correct |
48 |
Correct |
13 ms |
18012 KB |
Output is correct |
49 |
Correct |
14 ms |
19036 KB |
Output is correct |
50 |
Correct |
18 ms |
20828 KB |
Output is correct |
51 |
Correct |
17 ms |
17756 KB |
Output is correct |
52 |
Correct |
10 ms |
16476 KB |
Output is correct |
53 |
Correct |
6 ms |
15788 KB |
Output is correct |
54 |
Correct |
12 ms |
16988 KB |
Output is correct |
55 |
Correct |
14 ms |
18012 KB |
Output is correct |
56 |
Correct |
13 ms |
20192 KB |
Output is correct |
57 |
Correct |
11 ms |
18904 KB |
Output is correct |
58 |
Correct |
13 ms |
19036 KB |
Output is correct |
59 |
Correct |
14 ms |
20088 KB |
Output is correct |
60 |
Correct |
12 ms |
18524 KB |
Output is correct |
61 |
Correct |
38 ms |
26572 KB |
Output is correct |
62 |
Correct |
43 ms |
26604 KB |
Output is correct |
63 |
Correct |
50 ms |
26524 KB |
Output is correct |
64 |
Correct |
56 ms |
31812 KB |
Output is correct |
65 |
Correct |
62 ms |
43216 KB |
Output is correct |
66 |
Correct |
75 ms |
29708 KB |
Output is correct |
67 |
Correct |
55 ms |
26960 KB |
Output is correct |
68 |
Correct |
29 ms |
23788 KB |
Output is correct |
69 |
Correct |
51 ms |
25680 KB |
Output is correct |
70 |
Correct |
60 ms |
30112 KB |
Output is correct |
71 |
Correct |
51 ms |
40528 KB |
Output is correct |
72 |
Correct |
44 ms |
35016 KB |
Output is correct |
73 |
Correct |
50 ms |
39120 KB |
Output is correct |
74 |
Correct |
61 ms |
41556 KB |
Output is correct |
75 |
Correct |
51 ms |
38740 KB |
Output is correct |