#P16748. [GKS 2020 #A] Plates
[GKS 2020 #A] Plates
Problem Description
Dr. Patel has stacks of plates. Each stack contains plates. Each plate has a positive beauty value, describing how beautiful it looks.
Dr. Patel would like to take exactly plates to use for dinner tonight. If he would like to take a plate in a stack, he must also take all of the plates above it in that stack as well.
Help Dr. Patel pick the plates that would maximize the total sum of beauty values.
Input Format
The first line of the input gives the number of test cases, . test cases follow. Each test case begins with a line containing the three integers , and . Then, lines follow. The -th line contains integers, describing the beauty values of each stack of plates from top to bottom.
Output Format
For each test case, output one line containing Case #x: y, where is the test case number (starting from 1) and is the maximum total sum of beauty values that Dr. Patel could pick.
2
2 4 5
10 10 100 30
80 50 10 50
3 2 3
80 80
15 50
20 10
Case #1: 250
Case #2: 180
Hint
In Sample Case #1, Dr. Patel needs to pick plates:
- He can pick the top plates from the first stack ().
- He can pick the top plates from the second stack () .
In total, the sum of beauty values is .
In Sample Case #2, Dr. Patel needs to pick plates:
- He can pick the top plates from the first stack ().
- He can pick no plates from the second stack.
- He can pick the top plate from the third stack ().
In total, the sum of beauty values is .
Limits
.
.
.
The beauty values are between and , inclusive.
Test Set 1
.
Test Set 2
.