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: Accepted

Solution code:
q,h,s,d = map(int,input().split())
n = int(input())
q1 = q*4
h1 = h*2
q2 = q*8
h2 = h*4
s2 = s*2
b1 = 0
b2 = 0

if q1 <= h1 and q1 <= s:
    b1 = q1
elif h1 <= q1 and h1 <= s:
    b1 = h1
else:
    b1 = s


if  q2 <= h2 and q2 <= s2 and q2 <= d:
    b2 = q2
elif h2 <= q2 and h2 <= s2 and h2 <= d:
    b2 = h2
elif s2 <= q2 and s2 <= h2 and s2 <= d:
    b2 = s2
else:
    b2 = d

cnt1 = 0
cnt2 = 0

if b1*2 > b2:
    cnt1 = n//2
    cnt2 = n%2
    print((b2*cnt1)+(b1*cnt2))
else:
    print(b1*n)

Submission status: Accepted

Solution code:
Q,H,S,D = map(int, input().split())
N = int(input())

q = Q * 8
h = H * 4
s = S * 2
d = D

rlt = 0

lst1 = [Q, H, S, D]
lst2 = [q, h, s, d]
lst3 = [q, h, s]

while N > 0:
  if N >= 2:
    a = lst2.index(min(lst2))
  else:
    a = lst3.index(min(lst3))
  if a == 0:
    rlt += lst1[0] * N * 4
    N = 0
  elif a == 1:
    rlt += lst1[1] * N * 2
    N = 0
  elif a == 2:
    rlt += lst1[2] *N
    N = 0
  else:
    rlt += lst1[3] * (N // 2)
    N = N % 2

print(rlt)

Submission status: Accepted

Solution code:
T = list(map(int,input().split()))
n = int(input())*4
q_s = 1
h_s = 2
s_s = 4
d_s = 8

L = []
temp = 1
for i in range(4):
    s = temp
    v = T[i] / s
    L.append([T[i],s,v])
    temp *= 2

L.sort(key=lambda x: x[2])

ans = 0
for l in L:
    ans += (n // l[1])*l[0]
    n = n % l[1]

print(ans)

Submission status: Accepted

Solution code:
Q,H,S,D=map(int,input().split())
N=int(input())

r1=[4*Q,2*H,S,D/2]

if N%2==0:
    print(round(min(r1)*2)*N//2)
else:
    if r1.index(min(r1))<=2:
        print(round(min(r1)*N))
    else:
        print(N//2*D+min(r1[:3]))

Submission status: Accepted

Solution code:
Q, H, S, D = [int(x) for x in input().strip().split()]
N = int(input())
min_QHS = min(Q * 4, H * 2, S)
if min_QHS * 2 <= D:
  print(N * min_QHS)
else:
  print(D * (N // 2) + (N % 2) * min_QHS)

Submission status: Accepted

Solution code:
q,h,s,d=map(int,input().split())
n=int(input())
cost=0
if n>=2:
    cost+=n//2*min(q*8,h*4,s*2,d)
    n%=2
if n>=1:
    cost+=n//1*min(q*4,h*2,s)
    n%=1
if n>=0.5:
    cost+=n//0.5*min(q*2,h)
    n%=0.5
if n>=0.25:
    cost+=n//0.25*q
print(cost)

Submission status: Accepted

Solution code:
Q,H,S,D = map(int, input().split())
N = int(input())
Q *= 4
H *= 2
min_cost = min(Q,H,S)
res = 0
if N%2:
    N -= 1
    res += min_cost
if N != 0:
    res += N//2*min(2*min_cost,D)
print(res)

Submission status: Accepted

Solution code:
Q, H, S, D = map(int, input().split())
N = int(input())
one = min(4*Q, 2*H, S)
two = min(2*one, D)
print(N//2 * two + N % 2 * one)

Submission status: Accepted

Solution code:
def solve(Q, H, S, D, N):
    prices =[(int(0.25 * 4), Q),
             (int(0.5 * 4), H),
             (int(1.0 * 4), S),
             (int(2.0 * 4), D)]
    prices.sort(key=lambda x: x[1] / x[0])
    ans = 0
    N *= 4
    for p in prices:
        L = N // p[0]
        ans += L * p[1]
        N -= L * p[0]
    return ans


if __name__ == "__main__":
    Q, H, S, D = tuple(map(int, input().split(" ")))
    N = int(input())
    print(solve(Q, H, S, D, N))

Submission status: Accepted

Solution code:
q,h,s,d=map(int,input().split())
n=int(input())
if n==1:
  print(min(s,h*2,q*4))
elif n%2==0:
  print(min(int(n/2)*d,n*s,2*n*h,4*n*q))
else:
  print(min(int(n/2)*d+s,int(n/2)*d+2*h,int(n/2)*d+4*q,n*s,2*n*h,4*n*q))

Submission status: Accepted

Solution code:
Q,H,S,D=map(int,input().split())
N=int(input())
a=0
if N%2:
    a+=min(4*Q,2*H,S)
a+=N//2*min(8*Q,4*H,2*S,D)
print(a)

Submission status: Accepted

Solution code:
Q, H, S, D = map(int, input().split())
Q *= 4
H *= 2
N = int(input())
print(N // 2 * min(Q * 2, H * 2, S * 2, D) + N % 2 * min(Q, H, S))

Submission status: Accepted

Solution code:
q, h, s, d = map(int,input().split())
n = int(input())
d = min(d,s*2,h*4,q*8)
s = min(s,h*2,q*4)

ans = n//2 * d + n%2 * s

print(ans)

Submission status: Accepted

Solution code:
Q,H,S,D = map(int,input().split())
N = int(input())
A = min(Q*4,H*2,S)
if 2*A <= D:
    print(N*A)
else:
    print(N//2*D + N%2*A)

Submission status: Accepted

Solution code:
a,b,c,d=map(int,input().split())
n=int(input())
if n == 1:
  print(min(a*4,b*2,c))
elif n%2 == 0:
  print(min(a*4*n,b*2*n,c*n,d*n//2))
else:
  print(min(a*4*n,b*2*n,c*n,n//2*d+min(a*4,b*2,c)))

Submission status: Accepted

Solution code:
q,h,s,d = map(int,input().split())
n = int(input())
a = 0
if n%2 == 1:
  n -= 1
  a += 1
ans = n//2*min(8*q,4*h,2*s,d)+a*min(4*q,2*h,s)
print(ans)

Submission status: Accepted

Solution code:
q,h,s,d=map(int,input().split())
n=int(input())
n*=4
j=4*(2*q<h)+2*(2*h<s)+(4*q<s)
if j%4==0:
  if 2*s<d:
    print(s*(n//4))
  else:
    print(d*(n//8)+s*((n%8)//4))
  
if j==2 or j==3:
  if 4*h<d:
    print(h*(n//2))
  else:
    print(d*(n//8)+h*((n%8)//2))

if j==5 or j==7:
  if q*8<d:
    print(q*n)
  else:
    print(d*(n//8)+q*(n%8))

Submission status: Accepted

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

lst = [[1, q, q*4], [2, h, h*2], [4, s, s], [8, d, d/2]]
lst.sort(key=lambda x: x[2])

ans = 0
for i in range(4):
    volume = lst[i][0]
    price = lst[i][1]
    ans += price * (n//volume)
    n = n % volume

print(ans)

Submission status: Accepted

Solution code:
q,h,s,d = map(int,input().split())
N = int(input())
one = min(q*4,h*2,s)
print(min(one*N,d*(N//2)+one*(N%2)))

Submission status: Accepted

Solution code:
q,h,s,d = map(int, input().split())
n = int(input())
# print(min(q*8,h*4,s*2,d),min(q*8,h*4,s*2))
print((n//2 * min(q*8,h*4,s*2,d)) + (n%2 * min(q*4,h*2,s)))

Submission status: Accepted

Solution code:
Q,H,S,D = map(int,input().split())
N = int(input())
cnt = (N//2)*min(8*Q,4*H,2*S,D)
if N%2==1:
    cnt += min(4*Q,2*H,S)
print(cnt)

Submission status: Accepted

Solution code:
q, h, s, d = map(int, input().split())
n =int(input())
ans = min([4*n*q, 2*n*h, n*s, (n//2)*d+(n%2)*min(4*q, 2*h, s)])
print(ans)

Submission status: Accepted

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

if q*2 < h: h = q*2
if h*2 < s: s = h*2
if s*2 < d: d = s*2

ans = n//2*d
n -= n//2 * 2
ans += n*s
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

Q, H, S, D = map(int, input().split())
N = int(input())
S = min(S, 4*Q, 2*H)
D = min(D, 8*Q, 4*H, 2*S)
print(N//2*D+N%2*S)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
def main():
    Q, H, S, D = map(int,input().split())
    N = int(input())
    print((N//2)*min(Q*8,H*4,S*2,D)+(N%2)*min(Q*4,H*2,S))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
Q, H, S, D = map(int, input().split())
N = int(input())
Q1 = Q * 4
H1 = H * 2
D1 = D / 2
if min(Q1, H1, S) > D1:
  ans = D * (N // 2) + min(Q1, H1, S) * (N % 2)
else:
  ans = min(Q1, H1, S) * N
  
print(ans)

Submission status: Accepted

Solution code:
Q, H, S, D = map(int, input().split())
N = int(input())
l_1 = min((Q * 4), (H * 2), (S * 1))
l_2 = min((Q * 8), (H * 4), (S * 2), (D * 1))
ans = 0

if N == 1:
    ans = int(l_1)
elif N % 2 == 0:
    ans = int(l_2 * (N // 2))
else:
    ans = int(((N - 1) // 2) * l_2 + l_1)
print(ans)

Submission status: Accepted

Solution code:
q, h, s, d = map(int, input().split())
n = int(input())
o = min(4*q, 2*h, s)
if 2*o <= d:
	print(o * n)
else:
	print(d*(n//2) + o*(n%2))

Submission status: Accepted

Solution code:
import math
q,h,s,d = map(int,input().split())
n = int(input())
value = [0]*4
value[0] = q*4
value[1] = h*2
value[2] = s
value[3] = d/2
dum = min(value)
ind = value.index(dum)
if ind == 0:
    print(value[0]*n)
elif ind == 1:
    print(value[1]*n)
elif ind == 2:
    print(value[2]*n)
else:
    if n == 1:
        value.sort()
        print(value[1])
    elif n%2 == 0:
        print(math.floor(d*n//2))
    else:
        dum1 = (n//2)*d
        value.sort()
        print(math.floor(value[1]+dum1))

Submission status: Accepted

Solution code:
Q, H, S, D = map(int, input().split())
N = int(input())

price = [(8 * Q, 0.25), (4 * H, 0.5), (2 * S, 1.0), (D, 2.0)]
price.sort()

res = 0
if N % 2 == 0:
    res += N // 2 * price[0][0]
else:
    res += (N - 1) // 2 * price[0][0]
    for p in price:
        if p[1] == 2.0:
            continue
        res += p[0] // 2
        break

print(int(res))

Submission status: Accepted

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

l1 = min(h*2, q*4, s)
l2 = min(8*q, h*4, s*2, d)

ans = n//2 * l2 + n%2 * l1
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    Q, H, S, D = map(int, input().split())
    N = int(input())
    ans = N//2*min(8*Q, 4*H, 2*S, D) + N%2*min(4*Q, 2*H, S)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    q, h, s, d = map(int, input().split())
    N = int(input())

    one = min([4*q, 2*h, s])
    print(min((N//2)*d+one*(N % 2), N*one))


resolve()

Submission status: Accepted

Solution code:
q, h, s, d = list(map(int, input().split()))
n = int(input())
qpl = 4 * q
hpl = 2 * h
spl = s
dpl = d / 2
s_min = min(qpl, hpl, spl)
if dpl >= s_min:
    print(s_min * n)
elif n % 2 == 0:
    print(d * (n // 2))
else:
    print(d * (n // 2) + s_min)

Submission status: Accepted

Solution code:
q,h,s,d = [int(x) for x in input().split()]
n = int(input())

print((n//2) * min(8*q, 4*h, 2*s, d) + (n%2) * min(4*q, 2*h, s))

Submission status: Accepted

Solution code:
q,h,s,d = map(int, input().split())
n = int(input())
q*=4
h*=2
one = min(q,h,s)
c1 = n//2*d + n%2*one
c2 = n*one
print(min(c1,c2))

Submission status: Accepted

Solution code:
q,h,s,d=map(int,input().split())
n=int(input())
Q=4*q
H=2*h
S=s
D=d/2
b=[Q,H,S,D]
a=sorted(b)
if a[0]==D and n%2==1:
    ans=(n//2)*d+a[1]
elif a[0]==D:
    ans=(n//2)*d
else:
    ans=n*a[0]
print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
q, h, s, d = map(int, input().split())
n = int(input())
ans = 0
while n > 0:
    if n >= 2:
        ans += min(8 * q, 4 * h, 2 * s, d) * (n // 2)
        n = n % 2
    elif n == 1:
        ans += min(4 * q, 2 * h, s)
        break
print(ans)

Submission status: Accepted

Solution code:
Q, H, S, D = map(int, input().split())
N = int(input())

new_S = min(2 * min(2 * Q, H), S)
if 2 * new_S >= D:
    q, r = divmod(N, 2)
    print(q * D + r * new_S)
else:
    print(N * new_S)

Submission status: Accepted

Solution code:
Q,H,S,D = map(int, input().split())
N = int(input())

onelit = min((4*Q),(2*H),(S))

pattern1 = N * onelit
pattern2 = ((N//2)*D) + ((N%2) * onelit)

print(min(pattern1, pattern2))

Submission status: Accepted

Solution code:
q, h, s, d = map(int, input().split())
n = int(input())
m = 0
l = [q, min(q*2, h), min(q*4, h*2, s), min(q*8, h*4, s*2, d)]

m += (n // 2) * l[3] + (n % 2) * l[2]

print(int(m))

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    Q,H,S,D = MI()
    N = I()
    if(Q*2<H):
        H=2*Q
    if(H*2<S):
        S=H*2
    if(S*2<D):
        D=S*2
    print(N//2*D + ((N&1)*S))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
q,h,s,d = map(int, input().split())
n = int(input())
l1 = min(min(4*q,2*h),s)
l2 = min(2*l1, d)
print(n//2*l2 + n%2*l1)

Submission status: Accepted

Solution code:
q, h, s, d = map(int, input().split())
n = int(input())
s = min(4*q, 2*h, s)
ans = n//2*min(2*s, d)
ans += s*(n%2)
print(ans)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
Q,H,S,D = LI()
N = I()
min_1 = min(Q*4,H*2,S)
if 2*min_1<=D:
    ans = min_1*N
else:
    ans = N//2*D+(min_1 if N%2==1 else 0)
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    Q, H, S, D = map(int, input().split())
    N = int(input())

    ans = 0
    price_of_1_L = min(4 * Q, 2 * H, S)
    if D < 2 * price_of_1_L:
        n_D = N // 2
        ans += D * n_D
        N -= 2 * n_D
    ans += N * price_of_1_L

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
p = list(map(int, input().split()))
n = int(input())
eff = [p[0], p[1] / 2, p[2] / 4, p[3] / 8]
g = [0.25, 0.5, 1, 2]
total = 0
ans = 0
def calc(i):
    global total, ans
    k = eff.index(min(eff[: i + 1]))
    ans += int((n - total) // g[k] * p[k])
    total += (n - total) // g[k] * g[k]


while total != n:
    if n - total >= 2:
        calc(3)
    elif n - total >= 1:
        calc(2)
    elif n - total >= 0.5:
        calc(1)
    else:
        total += 0.25
        ans += p[0]
print(ans)

Submission status: Accepted

Solution code:
Q,H,S,D = list(map(int,input().split()))
N = int(input())*100
TL = sorted([(25,Q,8*Q),(50,H,4*H),(100,S,2*S),(200,D,D)],key=lambda x: x[2])
ans = 0
if N >= TL[0][0]:
    ans += (N//TL[0][0])*TL[0][1]
    N %= TL[0][0]
if N >= TL[1][0]:
    ans += (N//TL[1][0])*TL[1][1]
    N %= TL[1][0]
if N >= TL[2][0]:
    ans += (N//TL[2][0])*TL[2][1]
    N %= TL[2][0]
if N >= TL[3][0]:
    ans += (N//TL[3][0])*TL[3][1]
    N %= TL[3][0]
print(ans)

Submission status: Accepted

Solution code:
Q,H,S,D=map(int, input().split())
N=int(input())
a=min(8*Q,4*H,2*S,D)
b=min(4*Q,2*H,S)
if N%2==0:
  print(a*(N//2))
else:
  print(a*(N//2)+b)

Submission status: Accepted

Solution code:
from decimal import Decimal

Q, H, S, D = map(int, input().split())
N = int(input())

# 1リットルあたりの単価を出す
s = min([Q*4, H*2, S])
d = Decimal(D)/2

# Nが2で割れる時はリッターあたりの最安値*N
if N%2==0:
    print(int(N*min(s, d)))

# Nが2で割れない時は、N-1までは最安値で買って、残り1リットルはsの単価で買う
else:
    print(int((N-1)*min(s, d) + s))

Submission status: Accepted

Solution code:
Q, T, S, D = map(int, input().split())
N = int(input())

for_1L = min(4*Q, 2*T, S)
for_2L = min(2*for_1L, D)

print((N//2)*for_2L + (N%2)*for_1L)

Submission status: Accepted

Solution code:
# A - Ice Tea Store

Q, T, S, D = map(int, input().split())
N = int(input())

for_1L = min(4*Q, 2*T, S)
for_2L = min(2*for_1L, D)

print((N//2)*for_2L + (N%2)*for_1L)

Submission status: Accepted

Solution code:
Q, H, S, D = map(int, input().split())
N = int(input())
n = N // 2 * 2
ans =  min(n * Q * 4, n * H * 2, n * S, n * D // 2)
if N % 2 == 1:
    ans += min(Q * 4, H * 2, S)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[29]:


# Q, H, S, D = map(int, input().split())
# N = int(input())


# In[30]:


# volume = [0.25, 0.5, 1, 2]
# unit_c = [Q*4, H*2, S, D/2]
# act_c = [Q, H, S, D]

# mylist = [[volume[i], unit_c[i], act_c[i]] for i in range(len(volume))]
# mylist_sorted = sorted(mylist, key=lambda x: x[1])

# ans = 0
# target = N
# for v,c,a in mylist_sorted:
#     count = target//v
#     ans += count*a
#     target -= v*count 
# #     print(v, c, a, count, target)
#     if target == 0:
#         break
# print(int(ans))


# In[ ]:


q, h, s, d = map(int, input().split())
n = int(input())
 
cost_per_2l = min(q*8, h*4, s*2, d)
cost_per_1l = min(q*4, h*2, s)
 
a = n // 2
b = n % 2
 
print(a*cost_per_2l + b*cost_per_1l)

Submission status: Accepted

Solution code:
q , h , s , d = map(int,input().split())
n = int(input())
qb = q*8
hb = h*4
sb = s*2
db = d

if min(qb,hb,db,sb) != db:
    print(n*min(q*4,h*2,s))
elif min(qb,hb,db,sb) == db:
    if n % 2 == 0:
        print((n//2)*d)
    elif n % 2 == 1:
        ans = (n//2) * d
        ans += min(q*4,h*2,s)
        print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    q,h,s,d=map(int, input().split())
    n=int(input())
    s=min(4*q,2*h,s)
    if 2*s<=d:
        print(n*s)
    else:
        a,b=divmod(n,2)
        print(a*d+b*s)
resolve()

Submission status: Accepted

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

n = int(input())

price = [q,h,s,d]
base = [8,4,2,1]
quant = [1,2,4,8]

comp = []
for i in range(4):
    comp.append([price[i]*base[i],i])

comp.sort()
# print(comp)

ans = 0
n *= 4

for ind in range(4):
    tag = comp[ind][1]
    p = price[tag]
    q = quant[tag]
    pos = n//q
    # print(pos)
    if pos >= 0:
        ans += p*pos
        n -= q*pos
    else:
        continue

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8
q, h, s, d = map(int, input().split())
n = int(input())
# 必ず小数のパックは偶数個買わないといけない。1Lで比較
ans = (n // 2) * min(d, 2 * s, 4 * h, 8 * q) + (n % 2) * min(s, 2 * h, 4 * q)

print(ans)

Submission status: Accepted

Solution code:
Q,H,S,D=list(map(int,input().split()))
N=int(input())
ans=0
min_tea=min(Q*8,H*4,S*2,D)
ans+= (N//2) * min_tea
N-=(N//2)*2
min_tea=min(Q*4,H*2,S*1)
ans+= (N//1) * min_tea
print(ans)

Submission status: Accepted

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

cost_per_2l = min(q*8, h*4, s*2, d)
cost_per_1l = min(q*4, h*2, s)

a = n // 2
b = n % 2

print(a*cost_per_2l + b*cost_per_1l)

Submission status: Accepted

Solution code:
Q,H,S,D=map(int,input().split())
N=int(input())
if H > 2*Q:
    H=2*Q
if S > 2*H:
    S=2*H
if D < 2*S:
    ans = N//2*(D)+(N%2)*S
else:
    ans = N*S
print(ans)

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    Q,H,S,D=pin()
    N=int(input())
    Q*=4
    H*=2
    s=min(Q,H,S)
    t=N%2
    ans=0
    if s*2>D:
        ans+=D*(N//2)
        #print(ans)
        N=t
    ans+=N*s
    print(ans)
#%%submit!
resolve()

Submission status: Accepted

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

sorted_list = sorted([(q, 4), (h, 2), (s, 1), (d, 0.5)],
                     key=lambda t: t[0] * t[1])

cheapest = sorted_list[0]
if cheapest[1] == 0.5:
    # 2リットルが最安の場合
    second = sorted_list[1]
    cost = cheapest[0] * (n // 2) + second[0] * (n % 2) * second[1]
else:
    cost = cheapest[0] * cheapest[1] * n

print(cost)

Submission status: Accepted

Solution code:
Q, H, S, D = map(int, input().split())
N = int(input())

c_05 = min(2*Q, H)
c_1 = min(2*c_05, S)

if 2*c_1 <= D:
    print(c_1 * N)
else:
    if N % 2 == 0:
        print(D * (N//2))
    else:
        print(D * (N//2) + c_1)

Submission status: Accepted

Solution code:
q,h,s,d=map(int, input().split( ))
n=int(input())#ちょうど
n*=4
lst=[(q*4,q,1),(h*2,h,2),(s,s,4),(d/2,d,8)]
lst.sort()
ans=0
for _,t,x in lst:
    ans+=(n//x)*t
    n-=(n//x)*x
print(ans)

Submission status: Accepted

Solution code:
q,h,s,d=map(int, input().split())
n = int(input())
q*=4
h*=2
t = min(q, h, s)
ans=0
while n!=0:
    if n==1:
        ans+=t
        break
    if n%2==1:
        if 2*t < d:
            ans+=2*t*(n-1)//2
            n=1
        else:
            ans+=d*(n-1)//2
            n=1
    else:
        if 2*t < d:
            ans+=t*(n)
            n=0
        else:
            ans+=d*(n)//2
            n=0

print(ans)

Submission status: Accepted

Solution code:
q,h,s,d = map(int,input().split())
n = int(input())
print(min(q*n*4,h*n*2,s*n,(n//2)*d+(n%2)*s,(n//2)*d+(n%2)*h*2,(n//2)*d+(n%2)*q*4))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 23:33:40 2020

@author: shinba
"""

q,h,s,d = map(int,input().split())

n = int(input())

a = [4*q,2*h,s,d/2]

a.sort()

if a[0] != d/2:
    print(int(n*a[0]))

else:
    if n % 2 == 0:
        print(d*int(n/2))
    else:
        print(d*int(n/2)+int(a[1]))

Submission status: Accepted

Solution code:
Q,H,S,D = map(int,input().split())
N = int(input())

S = min(S,2*H,4*Q)
if N != 1:
  if 2*S <= D:
    print(S*N)
  else:
    print(D*(N//2) +(N%2)*S)
else:
  print(S)

Submission status: Accepted

Solution code:
def main():
    Q,H,S,D=map(int,input().split())
    N=int(input())
    S=min(S,2*(min(H,2*Q))) # lowest price
    print(S*N if 2*S<=D else (N//2)*D+(N%2)*S)

main()

Submission status: Accepted

Solution code:
q, h, s, d = map(int, input().split())
n = int(input())
q_cp = q*8
h_cp = h*4
s_cp = s*2
d_cp = d
ans = 0
if min(q_cp,h_cp,s_cp,d_cp)==q_cp:
    ans+=n*q*4
elif min(q_cp,h_cp,s_cp,d_cp)==h_cp:
    ans+=n*h*2
elif min(q_cp,h_cp,s_cp,d_cp)==s_cp:
    ans+=n*s
else:
    ans += n//2*d
    amari = n%2
    if min(q_cp, h_cp, s_cp) == q_cp:
        ans += amari*q*4
    elif min(q_cp, h_cp, s_cp) == h_cp:
        ans += amari*h*2
    elif min(q_cp, h_cp, s_cp) == s_cp:
        ans += amari*s
print(int(ans))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc019/tasks/agc019_a

q, h, s, d = map(int, input().split())
n = int(input())
ans = (n // 2) * min([q * 8, h * 4, s * 2, d]) + (n % 2) * min([q * 4, h * 2, s])
print(ans)

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
q, h, s, d = map(int, sys.stdin.readline().rstrip().split())
N = I()
D = d
qh = min(2*q, h)
S = min(2*qh, s)
x = min(2*S, D)
if N%2 == 0:
    print(N//2*x)
else:
    print(N//2*x + S)

Submission status: Accepted

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

q *= 4
h *= 2
d_ = d / 2

tmp = min(q, h, s)
ans = 0
if d_ < tmp:
    ans += d * (n // 2)
    ans += tmp * (n % 2)
else:
    ans += n * tmp

print(ans)

Submission status: Accepted

Solution code:
q, h, s, d = map(int, input().split())
n = int(input())
min_2l = min(8*q, 4*h, 2*s, d)
min_1l = min(4*q, 2*h, s)
if n % 2 == 0:
  cost = (n // 2) * min_2l
else:
  cost = (n // 2) * min_2l + min_1l
print(cost)

Submission status: Accepted

Solution code:
q, h, s, d = map(int, input().split())
n = int(input())
s = min(q*4, h*2, s)
if s*2 <= d: print(s*n)
else: print(d*(n//2) + s*(n%2))

Submission status: Accepted

Solution code:
q,h,s,d=map(int,input().split());n=int(input());print(n//2*min(8*q,4*h,2*s,d)+n%2*min(4*q,2*h,s))

Submission status: Accepted

Solution code:
q,h,s,d=map(int,input().split())
n=int(input())
m=n//2*min(8*q,4*h,2*s,d)+n%2*min(4*q,2*h,s)
print(m)

Submission status: Accepted

Solution code:
q,h,s,d = map(int,input().split())
n = int(input())
m = min(8*q,4*h,2*s,d)*(n//2) + min(4*q,2*h,s)*(n%2)
print(m)

Submission status: Accepted

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

L = min(4*q, 2*h, s)
L2 = min(2*L, d)

print((n//2)*L2 + (n%2)*L)

Submission status: Accepted

Solution code:
Q,H,S,D = map(int,input().split())
N = int(input())

ans = min(8 * Q,4 * H,2 * S ,D) * (N // 2) + min(4 * Q,2 * H,S) * (N % 2)

print(ans)

Submission status: Accepted

Solution code:
Q, H, S, D = map(int, input().split())
N = int(input())
Q *= 4
H *= 2
if(N == 1): print(min(Q, H, S))
elif(N == 2): print(min(Q * 2, H * 2, S * 2, D))
else:
    ans = 0
    if(N % 2):
        N = N - 1
        ans += min(N * Q, N * H, N * S, (N // 2) * D)
        ans += min(Q, H, S)
    else:
        ans += min(N * Q, N * H, N * S, (N // 2) * D)
    print(ans)

Submission status: Accepted

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

d1 = min(q*4, h*2, s)
if d1*2 < d:
    print(n*d1)
else:
    print(n//2*d + n%2*d1)

Submission status: Accepted

Solution code:
Q, H, S, D = map(int, input().split())
N = int(input())
l = min(4*Q, 2*H, S)
if 2*l > D:
  print(D*(N//2) + N%2 * l)
else:
  print(l*N)

Submission status: Accepted

Solution code:
q, h, s, d = map(int, input().split())
n = int(input())
if min(q*8, h*4, s*2)<=d:
    print(min(q*4, h*2, s)*n)
else:
    print(n//2*d+min(q*4, h*2, s)*(n%2))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

# A - Ice Tea Store
prices = list(map(int, input().split()))
n = int(input())

stores = []
units = [1, 2, 4, 8]
magnifications = list(reversed(units))

for i in range(4):
	compared_price = prices[i] * magnifications[i]
	store = [units[i], prices[i], compared_price]
	stores.append(store)

# 0:購入単位, 1:価格, 2:比較用の価格
stores.sort(key=lambda x:x[2])

amount = n * 4
ans = 0

for i in range(4):
	unit = stores[i][0]
	price = stores[i][1]

	ans += price * (amount//unit)
	amount %= unit

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
MOD = 1000000007

Q,H,S,D = map(int,input().split())
N = int(input())

#1L min
min_1L = min(min(4*Q,2*H),S)

min_2L = min(D,2*min_1L)

#num of 2L
print(N//2*min_2L + N%2*min_1L)

Submission status: Accepted

Solution code:
q,h,s,d,n=map(int,open(0).read().split())
if n%2==0:
  print(min(8*q,4*h,2*s,d)*(n//2))
else:
  print(min(8*q,4*h,2*s,d)*(n//2)+min(4*q,2*h,s))

Submission status: Accepted

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

ans = 0
#2Lの一番良い買い方をする
if n>=2:
    amount = n//2
    n-=amount*2
    ans+=min(q*8,h*4,s*2,d*1)*amount
if n==1:
    ans+=min(q*4,h*2,s*1)
print(ans)