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

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

i don’t see any problems but u can try to declare vector globally and when ur subtracting getting prefix sum it might get negative so u can do prexifixr-prefixl+mod then take mod

See prefix sum won’t ever get negative because every number is positive or 0…hence it shall always remain positive I guess

bro u need to know how mod works suppose we have mod 26 then if prefix sum increase than 26 we take modulus the ur finding sum of range so it means ur l might be bigger than r so this is causing r-l is becoming negative

I think you haven’t done that prefix sum optimization properly. Try to first write some recursive solution with O(k * n ^ 2) complexity and then go for the iterative version with the prefix optimization O(n * k) complexity. You can have a look at my solution it has both ways mentioned -

Also checkout the stream of Errichto on Atcoder dp on his youtube channel -