-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCANDY.cpp
More file actions
29 lines (26 loc) · 941 Bytes
/
CANDY.cpp
File metadata and controls
29 lines (26 loc) · 941 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
#include<stdio.h>
int main(){
long int t,i,sum=0,transfer=0,temp=0;
scanf("%ld",&t);
while(t!=-1){
sum=0;transfer=0;temp=0;
int b[t];
for(i=0;i<t;i++){
scanf("%d",&b[i]);
sum+=b[i];
}
temp=sum/t;
if(sum%t!=0){
printf("%d\n",-1);
}
else{
for(i=0;i<t;i++){
if(b[i]>temp)
transfer+=(b[i]-temp);
}
printf("%ld\n",transfer);
}
scanf("%ld",&t);
}
return 0;
}