Rally

Time limit6sMemory limit128 MB

Summary
Choose a subset of at most 25 stations and fuel amounts to minimize total driving time plus refueling stops.
Level

Medium7 of 10

Topics
Dynamic programming, Implementation, Math
Solved
No attempts yet

Problem

You are preparing for a car rally and must decide at which stations along the course to refuel.

The rules are:

  • Refueling at a station takes TT minutes (1≤T≤1041 \le T \le 10^4).
  • The tank holds at most Fmax⁡F_{\max} liters (103≤Fmax⁡≤10610^3 \le F_{\max} \le 10^6).
  • At the end of every kilometer driven, the fuel level FF instantly drops by ΔF\Delta_F liters (1≤ΔF≤501 \le \Delta_F \le 50).
  • The car's speed SS, in kilometers per minute, rises as the fuel level falls, but with an empty tank the car does not move at all: S={Smax⁡−C⋅Fif F>00if F=0S = \begin{cases} S_{\max} - C \cdot F & \text{if } F > 0 \\ 0 & \text{if } F = 0 \end{cases} where 103≤Smax⁡≤10610^3 \le S_{\max} \le 10^6, 1≤C≤1021 \le C \le 10^2, and the data always keeps S>0S > 0 while F>0F > 0 (that is, C⋅Fmax⁡<Smax⁡C \cdot F_{\max} < S_{\max}). The fuel level is constant during a kilometer, so driving that kilometer takes 1/S1/S minutes.
  • The rally is DD kilometers long (103≤D≤10610^3 \le D \le 10^6).
  • There are NN fuel stations (1≤N≤251 \le N \le 25).
  • Station ii is MiM_i kilometers from the start (0<Mi<D0 < M_i < D, and Mi<MjM_i < M_j whenever i<ji < j).

The car begins at kilometer 00 with a tank you fill for free and finishes at kilometer DD. You may refuel at any subset of the stations, adding any amount of fuel that keeps the tank within its capacity; each refueling stop costs TT minutes. The total time is the driving time (the sum of 1/S1/S over all DD kilometers) plus TT for every refueling stop you make.

Compute the minimum total time in which the rally can be completed.

Input

The input contains the following integers, each on its own line, in this order: TT, Fmax⁡F_{\max}, ΔF\Delta_F, Smax⁡S_{\max}, CC, DD, NN, and then M1,M2,…,MNM_1, M_2, \ldots, M_N.

Output

Print one line: the minimum total time in minutes, rounded to exactly six digits after the decimal point.

Examples3

  1. Example 1

    Input
    3
    20000
    2
    150000
    2
    30000
    2
    10000
    20000
    
    Expected output
    6.232620
    
  2. Example 2

    Input
    10000
    500000
    50
    1000000
    1
    9000
    3
    2500
    5000
    7500
    
    Expected output
    0.011957
    
  3. Example 3

    Input
    5
    1200
    1
    1000000
    1
    700
    1
    600
    
    Expected output
    0.000700