ATCODER EDUCATIONAL DP SERIES

My code for problem M(Candies) shows 3 wrong answers and I cannot figure out what exactly is wrong… Please help…
Problem Link: M - Candies
My Code : Submission #18376807 - Educational DP Contest

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 - Submission #17313827 - Educational DP Contest

Also checkout the stream of Errichto on Atcoder dp on his youtube channel - Dynamic Programming - AtCoder educational dp contest - YouTube

Hi @vin_04 I tried ur approach. so can we say that we cannot achieve nk solution using recursive dp apprach ???

@brasscobra I guess not.