#include<bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> a(2 * n);
int S = 0;
for(int i = 0; i < n; i++) {
cin >> a[i];
a[i + n] = a[i];
S += a[i];
}
vector<int> pref(2 * n + 1, 0);
for(int i = 0; i < 2 * n; i++) {
pref[i + 1] = pref[i] + a[i];
}
int ans = INT_MAX - 5;
//cerr << "moves:" << (n + 1) / 2 << '\n';
for(int i = 0; i < n; i++) {
int sum = pref[i + (n + 1) / 2] - pref[i];
//cerr << sum << ' ' << S - sum << '\n';
ans = min(ans, abs(sum - (S - sum)));
}
cout << (ans + S) / 2 << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |