spoj question

I am trying to solve http://www.spoj.com/problems/MIXTURES/
but getting wa. I tried numerous cases given in forum as well as comments all are correct but still wa…
link to solution http://ideone.com/W7Oz40

Google the question dude…anyways here’s a very good explanation answer
You can even use this