This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
if (n == 2) {
cout << (a[0] == a[1] ? 0 : 1) << "\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 |
---|
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... |
# | 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... |