#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;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
int ind = -1;
for (int i = 0; i < n; i++){
nsum += a[i];
if (nsum * 2 == sum){
ind = i;
break;
}
}
if (ind == -1){
cout << n - 1;
return 0;
}
vector <int> v[2];
for (int i = 0; i < n; i++){
if (i <= ind) v[0].push_back(a[i]);
else v[1].push_back(a[i]);
}
reverse(all(v[1]));
int i1 = 0, i2 = 0, ans = 0;
while (i1 < v[0].size()){
int j1 = i1 + 1;
int j2 = i1 + 1;
int sum1 = v[0][i1];
int sum2 = v[1][i2];
while (sum1 != sum2){
while (sum1 < sum2) sum1 += v[0][j1++], ans++;
while (sum2 < sum1) sum2 += v[1][j2++], ans++;
}
i1 = j1;
i2 = j2;
}
cout << ans;
}
Compilation message
nizin.cpp: In function 'int32_t main()':
nizin.cpp:44:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (i1 < v[0].size()){
~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
3072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
50 ms |
6264 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
63 ms |
8056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |