#include <bits/stdc++.h>
using namespace std;
#ifdef Ramzi
#include "debug.h"
#else
#define debug(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (n == 1) {
cout << 0 << "\n";
return 0;
}
int l = 0, r = n - 1;
int ans = 0;
while (l < r) {
if (a[l] != a[r]) {
if (a[l] < a[r]) {
while (l < n && a[l] < a[r]) {
a[l + 1] += a[l];
++l;
++ans;
}
} else {
while (r >= 0 && a[r] < a[l]) {
a[r - 1] += a[r];
++ans;
--r;
}
}
} else {
++l, --r;
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
456 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
856 KB |
Output is correct |
2 |
Correct |
4 ms |
856 KB |
Output is correct |
3 |
Correct |
5 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
2392 KB |
Output is correct |
2 |
Correct |
17 ms |
2752 KB |
Output is correct |
3 |
Correct |
24 ms |
3416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
4956 KB |
Output is correct |
2 |
Correct |
31 ms |
5200 KB |
Output is correct |
3 |
Correct |
36 ms |
5716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
6236 KB |
Output is correct |
2 |
Correct |
45 ms |
6228 KB |
Output is correct |
3 |
Correct |
38 ms |
6408 KB |
Output is correct |