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.



Sample input:
1500 2000 1600 3 2


Sample output:
7900

Submission status: Runtime Error

Solution code:
import sys
from sys import stdin, stdout,maxint
import math
from copy import deepcopy
rem=10**9+7
sys.setrecursionlimit(10 ** 6)
take = lambda: map(int, stdin.readline().split())



n,c=take()
ans=[]
ans2=[]
ans1=[]
ans3=[]
u=[0]
f=[0]
all=[[0,0]]
rev=[[0,0]]
for i in range(n):
    a,b=take()
    all.append([a,b])
    rev.append([c-a,b])
all.sort()
rev.sort()
#print all,rev
tot=0
en=0
for i in all:
    a,b=i
    tot+=b
    en=tot
    ans.append(en-a)
    ans1.append(en-2*a)

tot=0
en=0
for i in rev:
    a,b=i
    tot += b
    en = tot
    ans2.append(en - a)
    ans3.append(en-2*a)

fin=0
#print all,rev
#print ans,ans2
t=0
k=0
for i in range(len(ans)):
    t=max(t,ans[i])
    u.append(t)
    k=max(k,ans2[i])
    f.append(k)

#print ans,ans1,ans2,ans3,f
for i in range(n):
    fin=max(fin,ans1[i]+f[n-i])
    fin=max(fin,ans3[i]+u[n-i])
print fin

Submission status: Runtime Error

Solution code:
a=list(map(int, input().split()))
b=2＊a[3]＊a[2]
c=a[2]＊a[4]＊2+a[0]＊(a[3]-a[4])
d=2＊a[4]＊a[2]
e=a[2]＊a[3]＊2+a[1]＊(a[4]-a[3])
f=a[0]＊a[3]+a[1]＊a[4]
g=min(b,c,f)
h=min(d,e,f)
if a[3]>=a[4]:
    print(g)
else:
    print(h)

Submission status: Runtime Error

Solution code:
a=list(map(int, input().split()))
b=2＊a[3]＊a[2]
c=a[2]＊a[4]＊2+a[0]＊(a[3]-a[4])
d=2＊a[4]＊a[2]
e=a[2]＊a[3]＊2+a[1]＊(a[4]-a[3])
f=a[0]＊a[3]+a[1]＊a[4]
if a[3]>=a[4]:print(min(b,c,f))
else:print(min(d,e,f))

Submission status: Runtime Error

Solution code:
a=list(map(int, input().split()))
b=2＊a[3]＊a[2]
c=a[2]＊a[4]＊2+a[0]＊(a[3]-a[4])
d=2＊a[4]＊a[2]
e=a[2]＊a[3]＊2+a[1]＊(a[4]-a[3])
f=a[0]＊a[3]+a[1]＊a[4]
if a[3]>=a[4]:
    print(min(b,c,f))
else:
    print(min(d,e,f))

Submission status: Runtime Error

Solution code:
a=list(map(int, input().split()))
b=2＊a[3]＊a[2]
c=a[2]＊a[4]＊2+a[0]＊(a[3]-a[4])
d=2＊a[4]＊a[2]
e=a[2]＊a[3]＊2+a[1]＊(a[4]-a[3])
f=a[0]＊a[3]+a[1]＊a[4]
if a[3]>=a[4]:
  print(min(b,c,f))
else:
  print(min(d,e,f))

Submission status: Runtime Error

Solution code:
a=list(map(int, input().split()))
if a[0]+a[1]>=a[2]＊2:
    if a[3]>=a[4]:
        print (min(2＊a[3]＊a[2], (a[2]＊a[4]＊2+a[0]＊(a[3]-a[4]))))
    else:
        print (min(2＊a[4]＊a[2], (a[2]＊a[3]＊2+a[1]＊(a[4]-a[3]))))
else:
    print (a[0]＊a[3]+a[1]＊a[4])

Submission status: Runtime Error

Solution code:
def should_buy_ab(a,b,c):
    return 2 * c <= a + b


def solve(a,b,c,x,y):
    paid = 0

    if should_buy_ab(a,b,c):
        common = min(x, y)
        paid += (common * 2 * c)
        x -= common
        y -= common

        if x > 0:
            return paid + x * min(a, 2 * c)
        else:
            assert y > 0
            return paid + y * min(b, 2 * c)

    paid += x * a
    paid += y * b

    return paid


a, b, c, x, y = map(int, raw_input().split())
print solve(a,b,c,x,y)

Submission status: Runtime Error

Solution code:
a=list(map(int, input().split()))
if a[0]+a[1]>=a[2]＊2:
    if a[3]>=a[4]:
        print min(2＊a[3]＊a[2], (a[2]＊a[4]＊2+a[0]＊(a[3]-a[4])))
    else:
        print min(2＊a[4]＊a[2], (a[2]＊a[3]＊2+a[1]＊(a[4]-a[3])))
else:
    print (a[0]＊a[3]+a[1]＊a[4])

Submission status: Runtime Error

Solution code:
a=list(map(int, input().split()))
if a[0]+a[1]>=a[2]＊2:
    if a[3]>=a[4]:
        print max(2＊a[3]＊a[2], (a[2]＊a[4]＊2+a[0]＊(a[3]-a[4])))
    else:
        print max(2＊a[4]＊a[2], (a[2]＊a[3]＊2+a[1]＊(a[4]-a[3])))
else:
    print (a[0]＊a[3]+a[1]＊a[4])

Submission status: Runtime Error

Solution code:
a=list(map(int, input().split()))
if a[0]+a[1]>=a[2]＊2:
    if a[3]>=a[4]:
        print (a[2]＊a[4]＊2+a[0]＊(a[3]-a[4]))
    else:
        print (a[2]＊a[3]＊2+a[1]＊(a[4]-a[3]))
else:
    print (a[0]＊a[3]+a[1]＊a[4])

Submission status: Runtime Error

Solution code:
a=list(map(int, input().split()))
if a[0]+a[1]>=a[2]＊2 :
  if a[3]>=a[4]:
    print (a[2]＊a[4]+a[0]＊(a[3]-a[4]))
  else:
    print (a[2]＊a[3]+a[1]＊(a[4]-a[3]))
else:
  print (a[0]＊a[3]+a[1]＊a[4])

Submission status: Runtime Error

Solution code:
a=list(map(int, input().split()))
if a[0]+a[1]>=a[2]＊2 :
    if a[3]>=a[4]:
        print (a[2]＊a[4]+a[0]＊(a[3]-a[4]))
    else:
        print (a[2]＊a[3]+a[1]＊(a[4]-a[3]))
else:
    print (a[0]＊a[3]+a[1]＊a[4])

Submission status: Runtime Error

Solution code:
A, B, C, X, Y = map(int, input().split())

if X >= 2 and Y >= 2:
    ans = A * X + B * Y
    if C * 2 < A + B:
        z = min(X // 2, Y // 2)
        ans = A * (X - z * 2) + B * (Y - z * 2) + C * (z * 4)

        z = max(X // 2, Y // 2)
        ans = min(ans, A * max(0, (X - z * 2)) + B * max(0, (Y - z * 2)) + C * (z * 4))

print(ans)

Submission status: Runtime Error

Solution code:
l = map(int, raw_input().split())

if l[0] + l[1] < 2 * l[2]:
	if l[3] < l[4]:
		return l[3] * 2 * l[2] + (l[4] - l[3]) * l[1]
	else:
		return l[4] * 2 * l[2] + (l[3] - l[4])  * l[0]
else:
	return l[3] * l[0] + l[4] * l[1]