Problem Statement: 

There are N bricks (a1, a2, ...., aN). Each brick has length L1, L2, ...., LN). Make 2 highest parallel pillars (same length pillars) using the bricks provided.

Constraints:

1. There are N bricks. 5<=N<=50
2. Length of each brick. 1<=L<=1000
3. Sum of the bricks lengths <= 1000

Length of the bricks is not given in size order. There may be multiple bricks which may have the same length. Not all bricks have to be used to create the pillars.

Example:

1st Example- 

N = 5  

2, 3, 4, 1, 6

Possible Sets:  

(2, 6) and (3, 4, 1)

Answer: 8

My Approach:

Finding the maximum possible length of the 2 parallel pillars ie. floor(N/2). Then, using DP to find all the sum lengths that are possible using all the bricks. Starting with the highest possible sum possible <= floor(N/2), I take a single subset of elements that forms the sum. Then, again repeating the DP approach to find if the same sum can be formed using the remaining elements. If it can be formed, then the output is the highest possible sum, else using the 1st DP, check the next highest possible sum that can be formed and then, again iterate the whole process.

The problem with the above approach is that it checks for only one subset of elements to form the required sum. All possible subsets that can form the required sum should be checked and then for each of these subsets, using the remaining elements it should be checked if the same required sum can be formed. The trouble is the implementation of this in my current approach.

2nd Example-

N = 6  

3, 2, 6, 4, 7, 1

Possible Sets:  

(3, 2, 6) and (7, 4)

Answer: 11 

The problem in my code might come in this case depending on the order in which elements (brick lengths) are given as input. It might be possible that the first set is formed using the elements (3, 7, 1) = 11 but the second set (2, 6, 4) cannot form sum = 11. Hence, my code starts to find the next possible maximum sum .ie. 10 which is wrong.

Can someone suggest better approaches or possible improvements in my current approach.