Problem:


Score : 300 points

Problem Statement

You've come to your favorite store Infinitesco to buy some ice tea.

The store sells ice tea in bottles of different volumes at different costs.
Specifically, a 0.25-liter bottle costs Q yen, a 0.5-liter bottle costs H yen, a 1-liter bottle costs S yen, and a 2-liter bottle costs D yen.
The store has an infinite supply of bottles of each type.

You want to buy exactly N liters of ice tea. How many yen do you have to spend?

Constraints

1 \leq Q, H, S, D \leq 10^8

1 \leq N \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

Q H S D
N

Output

Print the smallest number of yen you have to spend to buy exactly N liters of ice tea.

Sample Input 1

20 30 70 90
3

Sample Output 1

150

Buy one 2-liter bottle and two 0.5-liter bottles. You'll get 3 liters for 90 + 30 + 30 = 150 yen.

Sample Input 2

10000 1000 100 10
1

Sample Output 2

100

Even though a 2-liter bottle costs just 10 yen, you need only 1 liter.
Thus, you have to buy a 1-liter bottle for 100 yen.

Sample Input 3

10 100 1000 10000
1

Sample Output 3

40

Now it's better to buy four 0.25-liter bottles for 10 + 10 + 10 + 10 = 40 yen.

Sample Input 4

12345678 87654321 12345678 87654321
123456789

Sample Output 4

1524157763907942



Sample input:
20 30 70 90
3


Sample output:
150

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    Q, H, S, D = map(int, input().split())
    N = int(input())
    q, h ,s ,d = [0.25, 0.5, 1, 2]
    cost_d = 0
    cost_s = 0
    cost_h = 0
    cost_q = 0
    if N > d:
        N_d=N
        while N_d > d:
            N_s -= d
            cost_d += D
        while N_d > s:
            N_s -= s
            cost_d += S
        while N_d > h:
            N_s -= h
            cost_d += H
        while N_d  > 0:
            N_s -= q
            cost_d += Q
    elif N > s:
        N_s = N
        while N_s > s:
            N_s -= s
            cost_s += S
        while N_s > h:
            N_s -= h
            cost_s += H
        while N_s > 0:
            N_s -= q
            cost_s += Q
    elif N > h:
        N_h = N 
        while N_h > h:
            N_h -= h
            cost_h += H
        while N_h > 0:
            N_h -= q
            cost_h += Q
    else:
        N_q = N
        while N_q > 0:
            N_q -= q
            cost_q += Q
    ans = min{cost_d, cost_s, cost_h, cost_q}
    print(ans)

Submission status: Runtime Error

Solution code:
#coding:UTF-8
#
#問題：AtCoder Grand Contest019 #A Ice Tea Store
#
#手法：入力Nは整数で与えられるので、Nが2以上のときは2リットル当たりの値段が安いドリンクをN/2個買い、
#Nが奇数だったら、残りの1リットルは1リットル当たりの値段が安いドリンク買う
sum=0#合計金額
#入力(0.25リットル,0.5リットル,1リットル,2リットル)
Q,H,S,D=input().split()
Q=int(Q)
H=int(H)
S=int(S)
D=int(D)
#入力チェック
if not(1<=Q<=10**8 and 1<=H<=10**8 and 1<=S<=10**8 and 1<=D<=10**8):
	print("input error1")
#1リットル当たりのQ,Hの値段QQ,HHを求める
QQ=Q*4
HH=H*2
#2リットル当たりのQ,H,Sの値段QQQ,HHH,SSSを求める
QQQ=8*Q
HHH=4*H
SSS=2*S
N=int(input())
#Nの入力チェック]
if not(1<=N<=10**9):
	print("input error2")
#N=1のとき、QQ,HH,Sの最小値がsumになる
if N==1:
	sum=min(QQ,HH,S)
else:#Nが2以上の時
	sum+=(N//2)*min(QQQ,HHH,SSS,D)
	if N%2==1:#Nが奇数のときは、sumにQQ,HH,Sの中の最小値を加える
		sum+=min(QQ,HH,S)
print()	
print(sum)
#print("Q,H,S,D=",Q,H,S,D)

Submission status: Runtime Error

Solution code:
n025, n05, n1, n2 = map(int, raw_input().split())
n = input()
ans = [0 for i in range(4)]


if n >= 2:
    arr = []
    arr.append(n025 * 8)
    arr.append(n05 * 4)
    arr.append(n1 * 2)
    arr.append(n2)
    for i in range(n / 2):
        m = arr.index(min(arr))
        if m == 0:
            ans[m] += 8
        elif m == 1:
            ans[m] += 4
        elif m == 2:
            ans[m] += 2
        else:
            ans[m] += 1

n = (n % 2)

for i in range(n):
    arr = []
    arr.append(n025 * 4)
    arr.append(n05 * 2)
    arr.append(n1)
    for i in range(n):
        m = arr.index(min(arr))
        if m == 0:
            ans[m] += 4
        elif m == 1:
            ans[m] += 2
        else:
            ans[m] += 1
        
tmp = 0
tmp += ans[0] * n025
tmp += ans[1] * n05
tmp += ans[2] * n1
tmp += ans[3] * n2

print tmp

Submission status: Runtime Error

Solution code:
q,h,s,d = map(int,input().split())
n = int(input())
n = n * 1000
a = 2000
b = 1000
c = 500
d2 = 250

tmp = int(n % a)
ans = int(n / a) * d
def max
if tmp > 0:
    ans1 = int(tmp/b) * s
    ans += int(tmp/b) * s
    tmp = int(tmp % b)

if tmp > 0:
    ans2 = int(tmp / c) * h
    tmp += int(tmp % c) * h
    tmp = int(tmp %c)

if tmp > 0:
    ans3 = int(tmp / d2) * q
    ans += int(tmp/d2) * q
    tmp = int(tmp % d2)
    tmp = int(tmp % d2)


print(ans)

Submission status: Runtime Error

Solution code:
contest1.py

Submission status: Runtime Error

Solution code:
def one_row():
	res = tuple(map(int, input().split()))
	return res
def multi_rows(n):
	return [one_line() for _ in range(

def a():
	import numpy as np
	q, h, s, d = one_row()
	l = [.25, .5, 1, 2]
	p = [q, h, s, d]
	n = int(input())
	price = [q*8, h*4, s*2, d]
	order = np.argsort(price)
	total = 0
	for i in order:
		times = n // l[i]
		total += times * p[i]
		n -= times * l[i]
	print(int(total))
	
a()

Submission status: Runtime Error

Solution code:
import sys
import math
def link( pool, f):
    def subset( a, b):
        return a[0] > b[0] and a[1] > b[0]
    notsubset = []
    max_value = 0
    for n,p in enumerate(pool): ##(X, Y, V)
        if subset(p[:2], f):
            max_value = max(max_value, p[2])
        else:
            notsubset.append(n)
    new_pool = [ pool[i] for i in notsubset]
    new_pool.append(
        f + [max_value + 1]
    )
    return new_pool
def orderit( fountains):
    return sorted( fountains, key=lambda x: max( x[0], x[1]), reverse=True)
def removeRedundant( fountains):
    return filter( lambda f:
        f if f[0] >= goal['x1'] and 
        f[0] <= goal['x2'] and
        f[1] >= goal['y1'] and
        f[1] <= goal['y2'] else None,
        fountains)
def transform( goal, fountains):
    if goal['x1'] > goal['x2']:
        goal['x1'] = -goal['x1']
        goal['x2'] = -goal['x2']
        for f in fountains:
            f[0] = -f[0]
    if goal['y1'] > goal['y2']:
        goal['y1'] = -goal['y1']
        goal['y2'] = -goal['y2']
        for f in fountains:
            f[1] = -f[1]
    return goal, fountains
def count_max( pool):
    print pool
    if not pool:
        return 0
    return max( map( lambda x: x[2], pool))
def travel( goal, fcount):
    r = 10
    res = 100 *( goal['x2'] - goal['x1'] + goal['y2'] - goal['y1'] )
    res += fcount * (  math.pi * 5 - 20 )
    return res
        
a,b,c,d = map(int, sys.stdin.readline().strip().split())
goal = {
    'x1': a,
    'y1': b,
    'x2': c,
    'y2': d,
}
N = int(sys.stdin.readline().strip())
fountains = []
for i in xrange(N):
    fountains.append(
        map( int, sys.stdin.readline().strip().split() )
    )
goal, fountains = transform( goal, fountains)
fountains = removeRedundant( fountains)
fountains = orderit( fountains)
pool = []
for f in fountains:
    pool = link(pool, f)
print travel( goal, count_max(pool))

Submission status: Runtime Error

Solution code:
Q, H, S, D = input().split()
Q, H, S, D = int(Q), int(H), int(S), int(D) # price 0.25 0.5 1.0 2.0
N = int(input())

per_2l_price = [Q*8, H*4, S*2, D]
per_1l_price = [Q*4, H*2, S]
per_05_price = [Q*2, H]
per_025_price = [Q]
needtobuy_l = N
needtobuy_m = 0


def st_min(lt):
    min_num = 0
    min_ = 1000000000000000000000000
    for i in range(len(lt)):
        if lt[i] < min_:
            min_num = i
            min_ = lt[i]
    return min_num
st_min


if needtobuy_l >= 2.0:
    mn = st_min(per_2l_price)
    needtobuy_m += per_2l_price[mn] * (needtobuy_l // 2.0)
    needtobuy_l -= 2.0 * (needtobuy_l // 2.0)
print(needtobuy_l, needtobuy_m)
input()
if needtobuy_l >= 1.0:
    mn = st_min(per_1l_price)
    needtobuy_m += per_1l_price[mn] * (needtobuy_l // 1.0)
    needtobuy_l -= 1.0 * (needtobuy_l // 1.0)
print(needtobuy_l, needtobuy_m)
input()
if needtobuy_l >= 0.5:
    mn = st_min(per_05_price)
    needtobuy_m += per_05_price[mn] * (needtobuy_l // 0.5)
    needtobuy_l -= 0.5 * (needtobuy_l // 0.5)
print(needtobuy_l, needtobuy_m)
input()
if needtobuy_l >= 0.25:
    needtobuy_m += Q * (needtobuy_l // 0.25)
    needtobuy_l -= 0.25 * (needtobuy_l // 0.25)

print(int(needtobuy_m))

Submission status: Runtime Error

Solution code:
a,b,c,d=[int(i) for i in input().split()]
M=[4*a,2*b,c,d/2]
N=int(input())

if M[0]==min(M):
    print(N*M[0])
elif M[1]==min(M):
    print(N*M[1])
elif M[2]==min(M):
    print(N*M[2])
else:
    if N%2==0:
        print(int(N//2*int(M[3]*2))
    else:
        if M[0]==min([4*a,2*b,c]):
            print(N//2*int(M[3]*2)+M[0])
        elif M[1]==min([4*a,2*b,c]):
            print(N//2*int(M[3]*2)+M[1])
        elif M[2]==min([4*a,2*b,c]):
            print(N//2*int(M[3]*2)+M[2])

Submission status: Runtime Error

Solution code:
volume = [1,2,4, 8]
value = tuple(map(int, input().split())
N = int(input())

counts = [10**10 for _ in range(N*4 + 1)]
counts[0] = 0

for i in range(4):
    for n in range(volume[i], N*4+1):
        counts[n] = min(counts[n], counts[n-volume[i]] + value[i])

print(counts[-1])

Submission status: Runtime Error

Solution code:
q,h,s,d = int(input().strip().split())
n = int(input())

h = min(h, q*2)
s = min(s, h*2)
d = min(d, s*2)

d_num, s_num = n//2, n%2
cost = d_num*d + s_num*s
print(cost)