-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path591.cpp
55 lines (44 loc) · 807 Bytes
/
591.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <vector>
#include <cstdint>
using namespace std;
void solve();
void calc();
int64_t numStacks;
int64_t temp;
int64_t counter = 1;
int64_t sum;
int64_t average;
int64_t answer;
vector<int64_t> heights;
int main() {
while (cin >> numStacks) {
if (numStacks != 0) {
solve();
} else {
break;
}
}
return 0;
}
void solve() {
heights.clear();
sum = 0;
for (int64_t i = 0; i < numStacks; i++) {
cin >> temp;
sum += temp;
heights.push_back(temp);
}
calc();
cout << "Set #" << counter++ << endl;
cout << "The minimum number of moves is " << answer << "." << endl << endl;
}
void calc() {
average = (sum / numStacks);
answer = 0;
for (int64_t i = 0; i < numStacks; i++) {
if (heights[i] > average) {
answer += (heights[i] - average);
}
}
}