Skip to content

Instantly share code, notes, and snippets.

@NigoroJr
Created December 30, 2014 06:33
Show Gist options
  • Save NigoroJr/a3c6f484c5e01b2f65b4 to your computer and use it in GitHub Desktop.
Save NigoroJr/a3c6f484c5e01b2f65b4 to your computer and use it in GitHub Desktop.
Problem 'sum' for the programming contest
#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