-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10137.cpp
More file actions
33 lines (32 loc) · 793 Bytes
/
10137.cpp
File metadata and controls
33 lines (32 loc) · 793 Bytes
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
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
double cost[1005];
while(cin>>n && n)
{
double average = 0.0,height=0.0,low = 0.0;
for(int i=0;i<n;i++)
{
cin>>cost[i];
average+=cost[i];
}
average = ((double)(int)(average*100/n+0.5))/100;
for(int i=0;i<n;i++)
{
if(cost[i]>average)
{
height += double(cost[i] - average);
}
else if(cost[i]<average)
{
low += double(average - cost[i]);
}
}
double ans = (height < low)?height:low ;
cout << "$"<<fixed << setprecision (2)<<ans << endl;
}
return 0;
}