City of Burgerland

Have you ever heard of The Burgerland City? The city is full of burger shops. You will surely find some shops of burgers wherever you will look around to any part of that city.


This is a companion discussion topic for the original entry at https://toph.co/p/city-of-burgerland

I have written a code for the problem which finds the shops having less capacity than cap.then it subtracts the capacity from cap and keeps adding all results of subtractions. Then it prints the sum. But the code gets wrong answer. Where is the mistake in my logic?