405096: GYM101790 F MK Ultra

Memory Limit:128 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. MK Ultratime limit per test1 secondmemory limit per test128 megabytesinputstandard inputoutputstandard output

N Unidentified Flying Saucers has arrived in "MK Ultra" spaceport. To identify saucers, they must first be washed. All saucers are arranged in the stack in particular order. The height of the i-th saucer from the top of the stack is Hi.

There are two washing machines in the spaceport. It is allowed to load several consequent saucers from the top of the stack to a washing machine if and only if this washing machine is free. The height of the buffer of the first washing machine is D1, and the height of the buffer of the second one is D2. It is impossible to load saucers in the buffer with a total height greater than the height of the corresponding buffer. If at some point of time both machines are free, they can perform loading in any order, but each loading operation should be atomic.

While there are flying saucers in the washing machine buffer, it pulls out and wash them one at a time. While all saucers from the buffer are not washed, the machine is considered busy. Washed saucers are sent for identification and are not involved in the washing process any more. The first machine washes saucer with height Hi for S1 × Hi seconds, and the second one washes it for S2 × Hi seconds.

Determine the minimum period of time needed to wash all flying saucers. The time for all processes except for directly washing saucers by wasing machines can be neglected. If necessary, the machines can stand idle for a while, if this minimizes the final result.

Input

The first line contains two integers S1 and S2 (1 ≤ S1, S2 ≤ 50).

The second line contains two integers D1 and D2 (1 ≤ D1, D2 ≤ 10000). It is guaranteed that any saucer can be washed in any washing machine.

The third line contains the number of flying saucers in the initial stack N (1 ≤ N ≤ 200).

The last line contains N integers Hi (1 ≤ Hi ≤ 50), denoting the heights of the saucers, starting from the top of the stack.

Output

Print single integer: the minimum number of seconds from the beginning of the washing until the moment when all flying saucers are sent for identification.

ExampleInput
4 3
14 11
10
1 2 3 9 5 2 7 3 2 8
Output
72
Note

In the example, the minimum time could be achieved as follows:

  • at time 0 the first machine loads saucer 1, the second loads 2;
  • at time 4 the first machine loads saucer 3;
  • at time 6, the second machine loads saucer 4;
  • at the time 16 the first machine loads saucers 5 - 7;
  • at time 33 the second machine loads saucers 8 - 9;
  • at time 48, the second machine loads saucer 10.

加入题单

上一题 下一题 算法标签: