1# Runtime: 760 ms (Top 68.15%) | Memory: 14.5 MB (Top 56.05%)234class Solution:5def tallestBillboard(self, rods: List[int]) -> int:6dp = collections.defaultdict(int)7dp[0] = 08for x in rods:9nxt = dp.copy()10for d, y in dp.items():11# init state12# ------|----- d -----| # tall side13# - y --| # low side1415# put x to tall side16# ------|----- d -----|---- x --|17# - y --|18nxt[d + x] = max(nxt.get(x + d, 0), y)1920nxt[abs(d - x)] = max(nxt.get(abs(d - x), 0), y + min(d, x))21dp = nxt22return dp[0]