Skip to content
Permalink
535f8e27c5
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
37 lines (33 sloc) 729 Bytes
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int students;
long payed[1005], average, owedA, owedB;
double x;
bool is_first = true;
for (cin >> students; students; cin >> students)
{
if (is_first)
is_first = false;
else
printf("\n");
average = owedA = owedB = 0;
for (int i = 0; i < students; ++i)
{
cin >> x;
payed[i] = int (x *= 100.0);
average += payed[i];
}
average /= students;
for (int i = 0; i < students; ++i)
if (payed[i] < average)
owedA += average - payed[i];
else
owedB += payed[i] - average;
long minOwed = ((owedA <= owedB) ? owedA : owedB);
printf ("$%.2lf", (minOwed / 100.0));
}
return 0;
}