https://onlinegdb.com/HJpqWVc4v

i stored the consecutive differences in the array and then added it till it is less than mid as soon as i placed a cow at a stall i made sum 0 this way i calculated if i can place all cows with a given difference as minimum or not plz check whatb is the logical error in my code and tell plzz.

hello @asinghal1_be19

your logic is correct infact it is same as what bhaiya taught in his live stream.
try long long in place of int . if still it fails then u can refer this ->