Cut at most M trees per evening with distinct machines to exactly D_i meters, and find the minimum total height after T days.
Medium7Dynamic programmingGreedySortingNo attempts yetTime limit2sMemory limit512 MBSubin grows N trees in the garden. Tree i is Hi meters tall right now and grows Ai meters every morning.
Subin owns M cutting machines. Machine i picks one tree whose height is greater than Di meters and cuts that tree down to exactly Di meters. A tree whose height is at most Di meters cannot be cut by machine i.
Every evening Subin picks some trees and cuts them. Picking no tree at all is allowed. Two conditions must hold.
So the trees cut on the same evening are paired with distinct machines, one machine per tree.
A day consists of the morning growth followed by the evening cutting. Write a program that finds the smallest possible sum of the tree heights after T days.
The first line contains the number of trees N and the number of machines M, separated by a space.
The second line contains H1,H2,…,HN separated by spaces.
The third line contains A1,A2,…,AN separated by spaces.
The fourth line contains D1,D2,…,DM separated by spaces.
The fifth line contains T.
Print the smallest possible sum of the tree heights after T days, on one line.
Suppose there are 2 trees. Tree 1 is 4 meters tall and grows 7 meters a day, tree 2 is 7 meters tall and grows 1 meter a day. There is a single machine with D1=7, and T is 1.
After the first morning, tree 1 is 4+7=11 meters tall and tree 2 is 7+1=8 meters tall. Cutting tree 1 down to 7 meters in the evening leaves a height sum of 15, and no smaller sum is reachable.