My code for problem M(Candies) shows 3 wrong answers and I cannot figure out what exactly is wrong… Please help…

Problem Link: https://atcoder.jp/contests/dp/tasks/dp_m

My Code : https://atcoder.jp/contests/dp/submissions/18376807

If anybody has a clue about what exactly the error is please help…