1 / 12
Dec 2008

i am gettin WA with my code.........in it i hav found the sum of all candies and checked whether its completely divisible by no of candies......if it is then i hav found the average of all the candies and then sum+=a[i]-avg(if no of candies in a packet is > avg) can nyone please explain wat is wrong in the algo........ question question

Ignore what i said. Sorry, misread your post.

Uh, no, when I said nothing, I meant nothing was wrong with his approach smile His approach gives 1, not 2.

astonished . I realised. Didn't read the '>' part. Hence the edit. I have no idea why it should return WA. Perhaps if the code were posted..

Annoying mistake it is. Your second printf("%d\n",sum) is outside the else loop. Change that for AC.

5 months later

Can you tell accurately the value that vi[1] is equal to at execution time?

10 years later

I’m using a similar approach but getting WA
The code is in python and intended.
Can anyone help?

while True:
x = int(input())
if(x==-1):
break
s = []
count = 0
for i in range(1,x+1):
j = int(input())
s.append(j)
if(sum(s)%x != 0):
print(-1)
break
av = sum(s)/x
for k in s:
if(k>av):
count = count+(k-av)
print (int(count))

    `indent preformatted text by 4 spaces`