Why is my code producing wrong output?

Please check my code it is producing wrong output

Link : https://ide.codingblocks.com/s/258881

firstly sort the stalls array!
secondly take the type as long long int to avoid any kind of overflow.