Hints for SRM 647, D1, 500-Pointer (CtuRobots)

James S. Plank

Fri Jan 30 11:56:42 EST 2015
Problem Statement.
This problem was a little overwhelming live, as I had no clue how to solve it. But I simply bit off what I could, and then the solution evolved.

Let's ask ourselves a few questions:

So now that we know how to calculate the best distance given a collection of robots, we can turn our attention to choosing the robots. It seems quite natural to me to sort the robots in decreasing order of capacity. Then start to think of a systematic way to calculate distances:

This feels like a dynamic program. Let's suppose our vector of ordered robots is v. Then, for each i, we want to know what the maximum distance is if we choose robot v[i] as the one to go last. That means we will not be choosing any robots with indices less than i. Moreover, suppose the cost of that robot is c. Then, we want to find the maximum amount of fuel that we can get from robots with indices greater than i, whose total cost is less than or equal to B-c.

So, define the procedure MF(index,budget) to be the maximum amount of fuel that can be donated by robots whose indices in v are greater than or equal to index and whose total cost is less than or equal to budget. This will be a recursive procedure with the following cases:

This gives you a recursive procedure to write, and of course you should see that it has to be memoized. The cache's maximum size will be v.size() * budget -- the constraints limit that to 5,000,000, so we're good to fit into topcoder's time limit.

Happy hacking!