#P16573. [USACO26OPEN] Haybale Stacks
[USACO26OPEN] Haybale Stacks
题目描述
Note: The time limit for this problem is .
Farmer John has stacks of haybales (), where the stack contains haybales (). He wants to remove all of these haybales and has () cows available to help him. If hired, the cow will repeat the following times () for a cost of ():
- If the stack contains at least haybales (), then the cow will remove one haybale.
- If the stack contains less than haybales, the cow does nothing.
For each stack, FJ wants to remove all of the haybales in it. He will do this by hiring cows in sequence (possibly the same cow more than once) until the stack becomes empty. Help FJ determine for each stack the minimum cost to empty it.
输入格式
The first line contains (), the number of independent tests. Each test is formatted as follows:
The first line contains an integer . The second line contains integers, .
The third line contains an integer . Then the next lines will contain .
It is guaranteed that the cows will be able to remove all the haybales in every stack. Additionally, it is guaranteed that the sum of over all tests does not exceed , and the sum of over all tests does not exceed .
输出格式
For each test, print space-separated integers, the integer being the cost of removing all the haybales in the stack.
2
3
15 100 10
4
101 1 1
1 4 8
9 3 5
15 2 3
3
15 100 10
4
101 1 1
1 1 5
9 1 8
15 1 3
29 155 21
73 328 50
提示
First test: For the last stack of initial size , we can hire cow once, which costs and will remove haybales twice (not thrice because the number of haybales turns to after the second one is removed). Then we can hire cow twice, removing the haybales, resulting in no haybales left. The total cost is .
Second test: This satisfies .
SCORING
- Inputs -:
- Inputs -:
- Inputs -:
- Inputs -:
- Inputs -: No additional constraints.