SPOJ Problem Set (classical) - Candy I

spoj

Problem:

Please find the problem here.

Solution:

A necessary condition is that the total number of candies can be distributed evenly, therefore we check if sum % N == 0. In that case, all bags with less candies must get filled, and there must be one available. So we sum the total number of candies needed to fill and that’s the answer.

Code: