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

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#include <stdio.h>
#include <cassert>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
typedef vector< vl > vvl;  //vector of vectors
#define X first
#define Y second
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(lo)b;i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(lo)d;j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRV(a) for(auto i : a)
#define INF 50000
#define MOD 1000000007
#define pb(a) push_back((a))
#define meme(a,b) memset((a),(b),sizeof((a)))

vector<lo> pset(1000001); // 1000 is just an initial number, it is user-adjustable.
void initSet(lo _size) { pset.resize(_size); REP (0, _size) pset[i] = i; }
lo findSet(lo i) { return (pset[i] == i) ? i : (pset[i] = findSet(pset[i])); }
void unionSet(lo i, lo j) { pset[findSet(i)] = findSet(j); }
bool isSameSet(lo i, lo j) { return findSet(i) == findSet(j); }

int main(){
    lo a,b,c,d,j,k,l,te,ans1,n,ans,arr[4];
    cin>>a>>b>>c>>d>>n;
    lo x = 100000000000000000;
    x = min(x,d);
    x = min(x,c+b*2);
    x = min(x,c+b+a*2);
    x = min(x,c+a*4);
    x = min(x,b+a*6);
    x = min(x,2*b+a*4);
    x = min(x,3*b+a*2);
    x = min(x,4*b);
    //x = min(x,b+a*6);
    x = min(x,a*8);
   // cout<<x<<endl;
    ans = 0;
    ans = (n/2)*x;
    n%=2;
    if(n==0)cout<<ans;
    else if(n==1){
        x = 100000000000000000;
        x = min(x,a*4);
        x = min(x,a*2+b);
        x = min(x,2*b);
        //x = min(x,3*b+a*2);
        x = min(x,c);
        ans +=x;
        cout<<ans;
    }
    return 0;
}