Skip to content

Commit e4cb0a3

Browse files
committed
atcoder/abc027B
1 parent f712d59 commit e4cb0a3

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

atcoder/abc027/B/main.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = int64_t;
5+
using ff = long double;
6+
7+
int N;
8+
vector<int> A;
9+
10+
int solve() {
11+
int M = accumulate(A.begin(), A.end(), 0, plus<int>());
12+
if (M % N != 0) return -1;
13+
M /= N;
14+
15+
int ans = 0;
16+
int acc = 0;
17+
for (auto ai : A) {
18+
acc += ai - M;
19+
if (acc != 0) ans += 1;
20+
}
21+
return ans;
22+
}
23+
24+
int main() {
25+
ios_base::sync_with_stdio(false);
26+
cin.tie(0); cout.tie(0);
27+
28+
cin >> N;
29+
A.assign(N, 0);
30+
for (auto &ai : A) cin >> ai;
31+
cout << solve() << endl;
32+
33+
return 0;
34+
}

0 commit comments

Comments
 (0)