DSA DP Contest!

Can anyone give me the code for bruteforce approach of this question having complexity O(N^3) ??
PROBLEM