This page is still under construction.

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

Evacuation

Time limit1sMemory limit128 MB

Summary
Given walking and elevator times, choose one floor where the descending elevator stops so that all waiting people reach floor 0 as fast as possible.
Level

Medium6 of 10

Topics
Greedy, Math
Solved
No attempts yet

Problem

The police have received a message that a bomb has been placed in the city's tallest building. A crisis team is formed and decides to evacuate the building as fast as possible. Luckily it is past five, so most people have already left. Using the building's security cameras, the crisis team can list the people still inside and the floors where they are.

The crisis team decides to use a single elevator for the evacuation, and this elevator happens to be at the top floor of the building. To minimize the risk of the bomb being triggered by the elevator's vibrations, the elevator will only move down, and it will move down only once. Over the intercom, everyone is asked to take the stairs (up or down) to the floor where the elevator will pick them up; the elevator is located right next to the stairs. Some people on the lower floors may instead leave the building using only the stairs.

The elevator needs a constant time to move down one floor and a constant time to close its doors (the time to open the doors is ignored). A person needs a constant time to walk one floor up or down the stairs. At the very beginning, the elevator's doors are closed.

Write a program that finds the fastest evacuation plan and reports how quickly everybody can reach the ground floor (floor 00).

Input

The first line contains a single integer: the number of test cases. Each test case has the following format:

  • A line with three positive integers mm, ss, and ww: mm (m≤100m \le 100) is the time the elevator takes to move down one floor, ss (s≤100s \le 100) is the time the elevator needs to close its doors after the last person on a floor has entered, and ww (w≤100w \le 100) is the time a person needs to walk one floor up or down the stairs.
  • A line with two integers nfnf and nwnw. Here nfnf (0<nf≤10000 < nf \le 1000) is the total number of floors in the building excluding the ground floor, and nwnw (0≤nw≤nf+10 \le nw \le nf + 1) is the number of floors on which people are waiting to be evacuated.
  • Then nwnw lines follow, each with one integer fif_i (0≤fi≤nf0 \le f_i \le nf): a floor on which a person is waiting. Within one test case all fif_i are distinct. By European convention the ground floor is numbered 00.

You may assume that all of the people involved fit into the elevator at once.

Output

For every test case, print a single line with one integer: the time needed to get everybody in the building down to the ground floor (floor 00).

Examples3

  1. Example 1

    Input
    3
    1 1 4
    5 3
    5
    1
    0
    1 1 4
    5 6
    0
    1
    2
    3
    4
    5
    10 10 20
    1000 0
    
    Expected output
    6
    8
    0
    
  2. Example 2

    Input
    1
    2 3 5
    10 1
    10
    
    Expected output
    23
    
  3. Example 3

    Input
    1
    5 1 2
    8 2
    3
    7
    
    Expected output
    14