You are given a rod of length n, and an array prices of size n which contains the prices of rods of lengths 1 to n. Find the maximum amount you can make if you cut up the rod optimally.
n: 8
A: [1, 3, 4, 5, 7, 9, 10, 11]
Result: 12
Explanation: Rods of length 2 and 6 cost: 3 + 9
The first line contains an integer âTâ denoting the number of test cases.
For each test case, the input has two lines:
For each test case, the output contains a line with one integer denoting the maximum amount possible.
3
8
1 3 4 5 7 9 10 11
6
3 5 8 10 14 15
7
2 8 11 14 15 19 21
12
18
27
1 <= T <= 10
1 <= n <= 5000
1 <= pricesi <= 106
1 <= answer <= 109