Monkey
Time limit2sMemory limit1024 MB
Given M allowed (x, y) handle pairs with banana counts on each handle, find the maximum total bananas collectable along a monotone path that only increases x or y.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Sorting, Combinatorics, Array
- Solved
- No attempts yet
Problem
Two pillars A and B stand side by side. Each pillar has handles, numbered 1 through from bottom to top. Each pillar has zero or more bananas hanging on it. is the number of bananas hanging on handle of pillar A, and is the number of bananas hanging on handle of pillar B. These values are integers between 0 and inclusive.
The monkey can grab handles on different pillars with its two arms. Note that it never grabs two handles on the same pillar. Also, the monkey cannot grab just any handle. A pair of handles the monkey can grab is written as , meaning it can grab handle of pillar A and handle of pillar B at the same time. The monkey then eats all bananas remaining on those two handles. As expected, a banana once eaten is gone. There are such ordered pairs in total.
Initially the monkey starts at one of the grabbable pairs of handles. When the monkey is at , it can move to another grabbable pair only if and , or and .
Naturally, the monkey wants to eat as many bananas as possible. Given the grabbable handles and the numbers of bananas hanging on them, write a program that finds the maximum number of bananas the monkey can eat.
Constraints
- Every ordered pair given as the input
Pis distinct, and satisfies , .