# Leetcode 1049 - Last stone weight II

You are given an array of integers stones where stones[i] is the weight of the ith stone.

We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:

• If x == y, both stones are destroyed, and
• If x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x.
At the end of the game, there is at most one stone left.

Return the smallest possible weight of the left stone. If there are no stones left, return 0.

Example:

Note:

• This is a 01 knapsack problem.
• The capacity of our bag is half of the total weight.
• The DP formula is DP[j] = max(DP[j], DP[j - stones[i]] + stones[i]).
• Iterate stones first, then the bag.
• The inner loop must be in descending order.