I was solving the problem on SPOJ — http://www.spoj.com/problems/MIXTURES/ and I came out with this approach — http://ideone.com/e.js/QWmLXf. This gives correct solution on few cases and otherwise incorrect. Can somebody point out what is the problem in this code.