INOI1301 - failing one test case

Problem
My solution

My Logic

I have made two DP arrays dp_f and dp_b.
Observe that moving backwards from any point to square 1 is the same as moving from square 1 to that point.
Each DP array stores the maximum sum possible.
dp_b includes the first element of the squares in all paths.

Can anyone provide a countercase or point out a hole in the logic?
@therealnishuz @everule1

N=2 k=2 is wrong. 2 mistakes.

Looking back at it, it gave a wrong output whenever the final answer was 0.
Here is the fixed version

Thanks @everule1

You don’t get RE, but out of bounds access when n=k on a[k+1]. That was the other error.