Training Site
Sideways banner

Containerisation

Input: Standard Input (stdin)
Output: Standard Output (stdout)
Memory limit: 64 megabytes
Time limit: 2.0 seconds

You have been put in charge of organising the containerisation of the next ship, consisting of two different types of cargo - gold ingots, and lead ingots.

Obviously, each ingot has quite a different weight. N containers will be loaded onto the ship. However, due to the varying construction quality and placement of each container, each has a different recommended capacity. The ith container has a recommended capacity of R_i kilograms.

Although you must fit all the ingots onto the ship, you decide to prioritise safety by minimising the weight by which any container can be overweight by. Specifically, find the minimum E, such that every container weighs no more than R_i + E kilograms.

Input

There are 5 integers, N, V, W, X and Y - the number of containers, the weight of the gold ingots, the weight of the lead ingots, the number of gold ingots and the number of lead ingots respectively.

The next N lines each contains a single integer R_i, the recommended capacity of the ith container.

Output

The minimum possible E \geq 0 such that no container weights more than E kilograms in excess of its recommended capacity.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq V, W \leq 2,000
  • 0 \leq X, Y \leq 2,000
  • 0 \leq R_i \leq 1,000,000,000

Subtasks

  • Subtask 1 (10%): There are only two containers N = 2.
  • Subtask 2 (10%): There are only gold ingots Y = 0.
  • Subtask 3 (30%): V, W, X, Y \leq 100
  • Subtask 4 (50%): No further constraints apply.

Explanation

In the first sample case, the optimal solution is to place 3 lead ingots in the first container (taking it over the recommended capacity by 14 kilograms), and 2 gold ingots in the second container (over-capacity by 12 kilograms).

In the second sample case, the 6 gold ingots can be split into 3 for the first container, 2 for the second, and 1 for the third. The second container carries 6 kilograms, or 2 kilograms over-capacity.

  • Sample Input 1

    2 6 8 2 3
    10 0
    

    Sample Output 1

    14
    
  • Sample Input 2

    3 3 1 6 0
    8 4 4
    

    Sample Output 2

    2
    
  • Sample Input 3

    5 2 3 5 2
    2 1 1 1 1
    

    Sample Output 3

    3