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>
#define int long long
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int N = 1000000 + 3;
int n, a[N], sum, nsum;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
cin >> n;
int mn = inf;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int i1 = 0, i2 = n - 1;
int ans = 0;
while (i1 < i2){
int j1 = i1, j2 = i2, sum1 = a[i1], sum2 = a[i2];
while (j1 < j2 && sum1 != sum2){
while (sum1 < sum2 && j1 < j2) sum1 += a[++j1], ans++;
while (sum2 < sum1 && j1 < j2) sum2 += a[--j2], ans++;
}
i1 = j1 + 1;
i2 = j2 - 1;
}
cout << ans;
}
Compilation message (stderr)
nizin.cpp: In function 'int32_t main()':
nizin.cpp:21:9: warning: unused variable 'mn' [-Wunused-variable]
int mn = inf;
^~
# | 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... |