This page is still under construction.

Parts of this page are still being built. What you see may change.

Travel Plan (Large)

Time limit5sMemory limit512 MB

Summary
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 NN inhabited planets, and all of them lie on one straight line. The ii-th planet sits at coordinate XiX_i. Earth is the first planet and sits at coordinate 0, so X1=0X_1 = 0.

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 FF 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 ii to another planet jj and burns ∣Xi−Xj∣|X_i - X_j| units of fuel on the way, and it cannot turn without landing.

Among the travel plans that burn at most FF 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 TT. Each test case takes three lines. The first line contains the number of planets NN. The second line contains the coordinates X1,X2,…,XNX_1, X_2, \dots, X_N. The third line contains the amount of fuel FF that you have.

Limits

  • 1≤T≤201 \le T \le 20
  • 2≤N≤302 \le N \le 30
  • 1≤F≤10171 \le F \le 10^{17}
  • −1015≤Xi≤1015-10^{15} \le X_i \le 10^{15}
  • X1=0X_1 = 0
  • All XiX_i 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 xx is the test case number starting from 1 and yy is the largest amount of fuel a plan burns.

Examples2

  1. Example 1

    Input
    3
    3
    0 10 -10
    40
    5
    0 1 2 3 4
    13
    5
    0 1 2 3 4
    7
    
    Expected output
    Case #1: 40
    Case #2: 12
    Case #3: NO SOLUTION
    
  2. Example 2

    Input
    3
    2
    0 5
    10
    2
    0 -1000000000000000
    1999999999999999
    2
    0 1000000000000000
    100000000000000000
    
    Expected output
    Case #1: 10
    Case #2: NO SOLUTION
    Case #3: 2000000000000000