Two Towers
Time limit2sMemory limit256 MB
Given passages joining two towers at listed floors and different elevator speeds, find the minimum time to travel between two given offices.
- Level
Medium5 of 10
- Topics
- Binary search, Implementation, Math, Array
- Solved
- No attempts yet
Problem
The company Mail.World has recently moved into a new office, which consists of two skyscraper towers of 109 floors each. On some floors they are joined by passages, along which one can walk from one tower to the other. There are n passages in total, and they join the towers on floors a1, a2, ..., a**n.
Artem works in tower b1 on floor L1. Today he needs to talk to his colleague Dmitry, who works in tower b2 on floor L2. Strangely enough, choosing the fastest way to get from Artem's workplace to Dmitry's workplace turns out not to be so simple.
Each tower has one elevator. The elevator in tower 1 covers one floor in u1 seconds, and the elevator in tower 2 in u2 seconds. Walking through a passage between the towers takes Artem t seconds.
Using this information, help Artem find the minimum time in which he can get from his workplace to Dmitry's workplace. The time to move within a floor of one tower and the time to wait for the elevator can be ignored.
In the first example, Artem simply has to ride the elevator of the first tower.
In the second example, the elevator in the second tower is substantially faster, so it is better for Artem to cross the passage to the second tower, ride the elevator to floor 10, return to the first tower, and ride the elevator in the first tower for one more floor.
Input
The first line contains a positive integer t, the number of test cases in the input. The descriptions of the test cases follow.
The first line contains n, the number of passages between the towers (1 ≤ n ≤ 105). The second line contains n distinct integers a1, a2, ..., a**n (1 ≤ a1 < a2 < ... < a**n ≤ 109). The next line contains three positive integers: u1, u2 and t (each lies in the range from 1 to 109). Finally, the next two lines contain two numbers each: b1, L1 and b2, L2, respectively (each of b1 and b2 is 1 or 2, 1 ≤ L1, L2 ≤ 109).
The total number of passages across all test cases in the input does not exceed 106.
Output
For each test case, output one number: the minimum time in seconds in which Artem can get from his workplace to Dmitry's workplace.