Problem:
Score : 300 points

Problem Statement

"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.

Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.

Constraints

1 ≤ A, B, C ≤ 5000

1 ≤ X, Y ≤ 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C X Y

Output

Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.

Sample Input 1

1500 2000 1600 3 2

Sample Output 1

7900

It is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.

Sample Input 2

1500 2000 1900 3 2

Sample Output 2

8500

It is optimal to directly buy three A-pizzas and two B-pizzas.

Sample Input 3

1500 2000 500 90000 100000

Sample Output 3

100000000

It is optimal to buy 200000 AB-pizzas and rearrange them into 100000 A-pizzas and 100000 B-pizzas. We will have 10000 more A-pizzas than necessary, but that is fine.

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        this.ACost = inpt[0];
        this.BCost = inpt[1];
        this.CCost = inpt[2];

        this.NeedA = inpt[3];
        this.NeedB = inpt[4];

        int CBuy = GetAns(0, Math.Max(NeedA * 2, NeedB * 2));
        int ans = Calc(CBuy);
        Console.WriteLine(ans);
    }

    private int GetAns(int min, int max) {
        if(max-min<=2) {
            int mid = (max + min) / 2;
            int v1 = Calc(min);
            int v2 = Calc(mid);
            int v3 = Calc(max);

            int minV = Math.Min(v1, Math.Min(v2, v3));
            if(minV == v1) {
                return min;
            }
            if(minV == v2) {
                return mid;
            }
            return max;
        }

        int mid1 = min + (max - min) / 3;
        int mid2 = max - (max - min) / 3;

        int val1 = Calc(min);
        int val2 = Calc(mid1);
        int val3 = Calc(mid2);
        int val4 = Calc(max);

        int minVal = Math.Min(val1, Math.Min(val2, Math.Min(val3, val4)));

        if(val1 == minVal) {
            return GetAns(min, mid1);

        } else if(val2 == minVal) {
            return GetAns(min, mid2);
        } else if(val3 == minVal) {
            return GetAns(mid1, max);
        } else {
            return GetAns(mid2, max);
        }
    }

    private int Calc(int cnt) {
        int total = cnt * CCost;

        int subNeedA = NeedA - cnt / 2;
        int subNeedB = NeedB - cnt / 2;
        if(subNeedA > 0) {
            total += subNeedA * ACost;
        }
        if(subNeedB>0) {
            total += subNeedB * BCost;
        }
        return total;
    }

    private int ACost;
    private int BCost;
    private int CCost;

    private int NeedA;
    private int NeedB;





    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"




1500 2000 500 90000 100000




";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}