This is the INOI16 problem 2: https://www.codechef.com/INOIPRAC/problems/INOI1602.
In this problem you are given a sequence of brackets, of length N: B, …, B[N], where each B[i] is one of the brackets. You are also given an array of Values: V,…, V[N].
Among all the subsequences in the Values array, such that the corresponding bracket subsequence in the B Array is a well-bracketed sequence, you need to find the maximum sum.
Note that closing bracket is opening bracket+K.
This was my code:
It works for the first four tests, then for none after. Where is the problem?