My approach was simple if language was rounded up simply use rounded up value else store them and then for users that did not respond I processed each user separately. Got WA and can’t figure out what is error in code.

P.S.: WA because I was using set, changed it to vector passed first two cases but failed last case. Link: https://ideone.com/ZvEAKP

Looks like, you have discarded the value of (Ci * 100) % n. You have rounded of (Ci * 100) / n, ignoring any exceeding fraction, and then distributed the remaining number of people.

For this test case correct answer is 101%, for val=1 it will give only 3% and 14 gives 45%, 4 gives 13%, 3 gives 10% so in total it gives 101% which is the correct answer.

Thanks, it was because I used set and it does not store duplicates. I changed it to vector and it passed first two test cases but not the last one, I even checked for overflow. Link: https://ideone.com/ZvEAKP

@rj25 - Can you first try changing all >=0.5 to >=0.4999999999 ? If that doesnt work, please comment the code so I can exactly get what you want. Your algo seems correct to me and I suspect it can be an implementation error.

Surprisingly it gave correct answer. I don’t understand why ? In question it is given 12.499 will be made 12 and its has to be 12.5 to be converted to 13. I changed >=0.5 to >=0.499999999. Can anyone explain this ?@vijju123

Since ancient times, the concept of witchcraft and black magic was used to describe unexplainable phenomenon. It was said that witches (male(?) and female) were able to manipulate forces of nature to perform their supernatural deeds. All the witches, however, had one common rule.

Never trust a floating point

Long story short, its nothing but rounding errors. The ideal fix was abs(value-(int) value)<=0.000001 . I just asked you to keep a gap of delta {10}^{-6}- though in a bit lenient fashion