#P12210. Little Blue's Building Blocks

    ID: 14314 Type: Default 1000ms 256MiB

Little Blue's Building Blocks

Little Blue's Building Blocks

Little Blue is an ardent enthusiast of building blocks and has many architectural models assembled from them. Recently, two new types of block sets – A and B – have been released. Little Blue goes to the block mall with his three backpacks, each having a fixed space capacity, with the intention of buying as many block sets as possible. He only buys the two new block sets. In each backpack, each block of type A occupies a space of $a$, and each block of type B occupies a space of $b$ (i.e. every block of the same type occupies the same amount of space). However, the mall has only a limited quantity of these blocks. Given the capacities of the three backpacks, the space usage of type A and type B blocks, and the available quantities of type A and type B blocks in the shop, determine the maximum total number of blocks Little Blue can take home.

Note: You have enough money to purchase any block as long as there is room in the backpacks, but the capacity of the backpacks and the shop inventory limit the number you can bring.

Formally: You are given three integers $c_1$, $c_2$, $c_3$ representing the capacities of the three backpacks. You are also given two integers $a$ and $b$ representing the space requirements for block types A and B respectively. Finally, you are given two integers $A$ and $B$ which denote the available units of type A and type B blocks, respectively. In each backpack, if you place $x$ blocks of type A and $y$ blocks of type B then the condition

x×a+y×bcix \times a + y \times b \leq c_i

must hold for the $i$-th backpack. Also, the total number of type A blocks used across all backpacks cannot exceed $A$, and similarly for type B blocks the total number cannot exceed $B$. Your task is to choose nonnegative integers $x_i$ and $y_i$ (for $i=1,2,3$) such that

i=13(xi+yi)\sum_{i=1}^3 (x_i + y_i)

is maximized while satisfying the above constraints.

inputFormat

The input consists of three lines:

  1. The first line contains three space-separated integers c1 c2 c3 — the capacities of the three backpacks.
  2. The second line contains two space-separated integers a b — the space occupied by one block of type A and type B respectively.
  3. The third line contains two space-separated integers A B — the number of available blocks of type A and type B in the shop, respectively.

outputFormat

Output a single integer — the maximum total number of blocks Little Blue can take home.

sample

3 4 5
1 2
6 3
9