-
Notifications
You must be signed in to change notification settings - Fork 0
/
candy1.c
48 lines (34 loc) · 1013 Bytes
/
candy1.c
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
#include<stdio.h>
int main(){
while(1)
{
int t;
scanf("%d",&t);
if(t==-1)
break;
else{
int i=0;
int arr[t];
while(i<t)
{
scanf("%d",&arr[i]);
i++;
}
long int sum=0;
for(i=0;i<t;i++)
sum=sum+arr[i];
double avg=sum/t;
if(sum%t==0)
{
int moves=0;
for(i=0;i<t;i++)
if(arr[i]>avg)
moves=moves+(arr[i]-avg);
printf("%d\n",moves);
}
else
printf("-1\n");
}
}
return 0;
}