Created
December 30, 2014 06:33
-
-
Save NigoroJr/a3c6f484c5e01b2f65b4 to your computer and use it in GitHub Desktop.
Problem 'sum' for the programming contest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <numeric> | |
#include <cstdio> | |
int main() { | |
int set = 1; | |
int num; | |
while (true) { | |
std::cin >> num; | |
std::vector<int> v; | |
if (num == 0) | |
break; | |
for (int i = 0; i < num; i++) { | |
int n; | |
std::cin >> n; | |
v.push_back(n); | |
} | |
int total = 0; | |
for (int i : v) | |
total += i; | |
std::cout << total << std::endl; | |
total /= v.size(); | |
int count = 0; | |
for (int i : v) | |
count += std::abs(i - total); | |
count /= 2; | |
printf("Set #%d\nThe minimum number of moves is %d.\n", set, count); | |
set++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment