Link to the code : https://ide.codingblocks.com/s/228438
Getting wrong answer. please fix my code
@Arnav7 problem is with last_cow variable, you are not updating it correctly.
It should be last_cow = stalls[i] because according to your code you are trying to store the last cow selected.
Also use long long int because the constraints are large.
Rest all other things are fine, just do these corrections your code will pass.
Also mark this doubt as resolved after you are done with this question.