Travel Plan (Large)
Time limit5sMemory limit512 MB
Visit every planet on a line exactly once and return to Earth, maximizing total travel distance without exceeding the fuel limit.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Sorting, Math
- Solved
- No attempts yet
Problem
Antarctic astronomers have an observation they have not announced yet: space holds inhabited planets, and all of them lie on one straight line. The -th planet sits at coordinate . Earth is the first planet and sits at coordinate 0, so .
Excited by this, you plan a trip that visits all of them. Unknown planets are dangerous, so you leave Earth, visit each of the other planets exactly once, and return to Earth. You have units of fuel, and you want to burn as much of it as you can so that the final landing on Earth is safer. Your spaceship is basic. It flies in a straight line from a planet to another planet and burns units of fuel on the way, and it cannot turn without landing.
Among the travel plans that burn at most units of fuel, find the one that burns the most, and print the amount of fuel it burns.
Input
The first line contains the number of test cases . Each test case takes three lines. The first line contains the number of planets . The second line contains the coordinates . The third line contains the amount of fuel that you have.
Limits
- All are different.
Output
For each test case, print one line. Print Case #x: NO SOLUTION when no such travel plan exists, and Case #x: y otherwise, where is the test case number starting from 1 and is the largest amount of fuel a plan burns.