Problem:
Problem A: Rental DVD Shop NEO
Problem
僕はレンタルDVDショップ、「NEO」でアルバイトを始めた。まずはこの店の料金システムを勉強することになった。
レンタルDVDは旧作、準新作、新作の3種類存在し、1本のレンタル料金がそれぞれ
a
円、
b
円、
c
円である。
会計の際に以下に示すセットレンタルを複数回適用することができる。
まだセットレンタルを適用していないDVDを数本選ぶ。
選んだDVDの本数が
d
本以上の場合、選んだDVDの合計金額が、
(選んだDVDの本数)
*
e
円を超える場合は、それらを
(選んだDVDの本数)
*
e
円でレンタル出来る。
選んだDVDの本数が
d
本未満の場合、選んだDVDの合計金額が
d
*
e
円を超える場合は、それらを
d
*
e
円でレンタル出来る。
上記に当てはまらない場合、選んだDVDは通常料金でレンタルとなる。
ここで僕はある問題に気づいた。セットレンタルはレジに通した時に自動的に適用されるのではなく、手動で適用しているのだ。これでは最適ではない（もっと安くなる余地がある）セットレンタルの適用をしてしまう可能性がある。これではクレームが発生しかねない。僕はクレーム対応が嫌いなので、セットレンタルを最適に適用した時の料金を計算するプログラムを作成することにした。
Input
入力は複数のデータセットからなる。
各データセットは以下で表される。
1行目は5つの整数
a
,
b
,
c
,
d
,
e
がスペース区切りで与えられる。
2行目にはレンタル本数が与えられる。3つの整数
na
,
nb
,
nc
がスペース区切りで与えられる。それぞれ旧作、準新作、新作のDVDの本数を表す。
入力の終わりは5つのゼロからなる。
a
b
c
d
e
na
nb
nc
Constraints
入力は以下の条件を満たす。
入力に含まれる値はすべて整数
0 <
a
<
b
<
e
<
c
≤ 1000
0 <
d
≤ 100000
0 ≤
na
,
nb
,
nc
≤ 100000
0 <
na
+
nb
+
nc
データセットの数は100個以下
Output
各データセットにつき、セットレンタルを最適に適用した時の料金を1行に出力せよ。
Sample Input
70 100 340 4 200
1 1 4
70 100 340 4 200
0 1 3
70 100 340 4 200
1 1 2
0 0 0 0 0
Sample Output
970
800
800

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

long long A, B, C, D, E;
long long NA, NB, NC;

int main() {
	while (true) {
		// Step 1. Input
		cin >> A >> B >> C >> D >> E; if (A + B + C + D + E == 0) break;
		cin >> NA >> NB >> NC;

		// Step 2. Easy Case
		if (NC >= D) {
			cout << NC * E + NB * B + NA * A << endl;
		}
		
		// Step 3. Hard Case
		else {
			vector<long long> vec;
			for (int i = 0; i < NC; i++) vec.push_back(C);
			for (int i = 0; i < NB; i++) vec.push_back(B);
			for (int i = 0; i < NA; i++) vec.push_back(A);
			long long cost2 = NA * A + NB * B + NC * C;
			long long cost1 = D * E;
			for (int i = D; i < vec.size(); i++) cost1 += vec[i];
			cout << min(cost1, cost2) << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 6976
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using namespace std;

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int main() {
    ll a, b, c, d, e;
    while (cin >> a >> b >> c >> d >> e) {
        if (a == b and b == c and c == d and d == e and a == 0) break;
        ll na, nb, nc;
        cin >> na >> nb >> nc;

        // 新作の値段は，制約よりEより高いので，新作はセットにするほうが良い
        if (nc >= d) {
            // 新作すべてをセットにして，d本以上にする場合
            // それ以外のをセットにしてしまうと，制約より旧作，準新作の値段よりeのほうが高いのでやらないほうが良い
            ll ans = a * na + b * nb + e * nc;
            cout << ans << endl;
        }
        else {
            // dの本数が小さい場合のみ，加えた方が良いかというのを準新作のほうから見ていく？

            ll ans = a * na + b * nb;
            if (nc > 0) ans += d * e;
            //cout << ans << endl;

            ll tmpd = d - nc;

            ll tmpb = nb, tmpa = na, cnt = nc;
            while (true) {
                // セットに含める
                if (tmpb > 0) {
                    tmpb--;
                    tmpd--;
                    ++cnt;
                }
                else if (tmpa > 0) {
                    tmpa--;
                    tmpd--;
                    cnt++;
                }
                else {
                    if (tmpd > 0) {
                        if (ans > d * e) {
                            ans = d * e;
                        }
                    }
                    else {
                        if (ans > cnt * e) {
                            ans = cnt * e;
                        }
                    }
                    break;
                }

                if (tmpd > 0) {
                    if (ans > a * tmpa + b * tmpb + d * e) {
                        ans = a * tmpa + b * tmpb + d * e;
                    }
                }
                else {
                    if (ans > a * tmpa + b * tmpb + cnt * e) {
                        ans = a * tmpa + b * tmpb + cnt * e;
                    }
                }
            }

            cout << min(a * na + b * nb + c * nc, ans) << endl;
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3092
final_rank: 4

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
long long a, b, c, d, e, na, nb, nc;
long long F[500000];
long long price(long long L) {
	if (L < nc)return c;
	if (L < nb + nc)return b;
	return a;
}
long long ruisekiwa(long long L, long long R) {
	if (L >= R)return 0;
	if (L == 0)return F[R - 1];
	return F[R - 1] - F[L - 1];
}
int main() {
	while (true) {
		cin >> a >> b >> c >> d >> e; if (a == 0)break;
		cin >> na >> nb >> nc;
		long long n = na + nb + nc, minx = na*a + nb*b + nc*c;
		for (long long i = 0; i < 500000; i++)F[i] = 0;
		for (long long i = 0; i < n; i++)F[i] = price(i);
		for (long long i = 1; i < n; i++)F[i] += F[i - 1];

		for (long long i = 0; i <= n; i++) {
			long long set1 = ruisekiwa(0, i);
			long long set2 = ruisekiwa(i, min(n, i + d));
			long long set3 = ruisekiwa(min(n, i + d), n);
			if (i >= d) {
				if (set1 >= i*e)set1 = i*e;
			}
			if (i < d) {
				if (set1 >= d*e)set1 = d*e;
			}
			if (set2 >= d*e)set2 = d*e;
			minx = min(minx, set1 + set2 + set3);
		}
		cout << minx << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 6992
final_rank: 11

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
long long a, b, c, d, e, na, nb, nc;
long long F[500000];
long long price(long long L) {
	if (L < nc)return c;
	if (L < nb + nc)return b;
	return a;
}
long long ruisekiwa(long long L, long long R) {
	if (L >= R)return 0;
	if (L == 0)return F[R - 1];
	return F[R - 1] - F[L - 1];
}
int main() {
	while (true) {
		cin >> a >> b >> c >> d >> e; if (a == 0)break;
		cin >> na >> nb >> nc;
		long long n = na + nb + nc, minx = na*a + nb*b + nc*c;
		for (long long i = 0; i < 500000; i++)F[i] = 0;
		for (long long i = 0; i < n; i++)F[i] = price(i);
		for (long long i = 1; i < n; i++)F[i] += F[i - 1];

		for (long long i = d; i <= n; i++) {
			long long set1 = ruisekiwa(0, i);
			long long set2 = ruisekiwa(i, min(n, i + d));
			long long set3 = ruisekiwa(min(n, i + d), n);
			if (set1 >= i*e)set1 = i*e;
			if (set2 >= d*e)set2 = d*e;
			minx = min(minx, set1 + set2 + set3);
		}
		cout << minx << endl;
	}
	return 0;
}
accuracy: 0.8
time_ms: 80
memory_kb: 6988
final_rank: 14

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
long long a, b, c, d, e, na, nb, nc;
long long F[500000];
long long price(long long L) {
	if (L < nc)return c;
	if (L < nb + nc)return b;
	return a;
}
long long ruisekiwa(long long L, long long R) {
	if (L >= R)0;
	if (L == 0)return F[R - 1];
	return F[R - 1] - F[L - 1];
}
int main() {
	while (true) {
		cin >> a >> b >> c >> d >> e; if (a == 0)break;
		cin >> na >> nb >> nc;
		long long n = na + nb + nc, minx = na*a + nb*b + nc*c;
		for (long long i = 0; i < 500000; i++)F[i] = 0;
		for (long long i = 0; i < n; i++)F[i] = price(i);
		for (long long i = 1; i < n; i++)F[i] += F[i - 1];

		for (long long i = d; i <= n; i++) {
			long long set1 = ruisekiwa(0, i);
			long long set2 = ruisekiwa(i, min(n, i + d));
			long long set3 = ruisekiwa(min(n, i + d), n);
			if (set1 >= i*e)set1 = i*e;
			if (set2 >= d*e)set2 = d*e;
			minx = min(minx, set1 + set2 + set3);
		}
		cout << minx << endl;
	}
	return 0;
}
accuracy: 0.8
time_ms: 80
memory_kb: 6992
final_rank: 15

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
int a, b, c, d, e, na, nb, nc;
int F[500000];
int price(int L) {
	if (L < nc)return c;
	if (L < nb + nc)return b;
	return a;
}
int ruisekiwa(int L, int R) {
	if (L >= R)0;
	if (L == 0)return F[R - 1];
	return F[R - 1] - F[L - 1];
}
int main() {
	while (true) {
		cin >> a >> b >> c >> d >> e; if (a == 0)break;
		cin >> na >> nb >> nc;
		int n = na + nb + nc, minx = na*a + nb*b + nc*c;
		for (int i = 0; i < 500000; i++)F[i] = 0;
		for (int i = 0; i < n; i++)F[i] = price(i);
		for (int i = 1; i < n; i++)F[i] += F[i - 1];

		for (int i = d; i <= n; i++) {
			int set1 = ruisekiwa(0, i);
			int set2 = ruisekiwa(i, min(n, i + d));
			int set3 = ruisekiwa(min(n, i + d), n);
			if (set1 >= i*e)set1 = i*e;
			if (set2 >= d*e)set2 = d*e;
			minx = min(minx, set1 + set2 + set3);
		}
		cout << minx << endl;
	}
	return 0;
}
accuracy: 0.8
time_ms: 70
memory_kb: 5040
final_rank: 13

code_snippet: #include <vector>
#include <iostream>
using namespace std;
int a, b, c, d, e, x, y, z;
int main() {
	while(cin >> a >> b >> c >> d >> e, a) {
		cin >> x >> y >> z;
		vector<int> v;
		for(int i = 0; i < z; i++) v.push_back(c);
		for(int i = 0; i < y; i++) v.push_back(b);
		for(int i = 0; i < x; i++) v.push_back(a);
		int g = a * x + b * y + c * z, sum = 0, ret = g;
		for(int i = 1; i <= v.size(); i++) {
			sum += v[i - 1];
			if(i >= d) {
				if(sum > i * e) ret = min(ret, g - (sum - i * e));
			}
			else {
				if(sum > d * e) ret = min(ret, g - (sum - d * e));
			}
		}
		cout << ret << endl;
	}
}
accuracy: 1
time_ms: 50
memory_kb: 6068
final_rank: 9

code_snippet: #include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int a, b, c, d, e, na, nb, nc;
    while (cin >> a >> b >> c >> d >> e, a) {
        cin >> na >> nb >> nc;
        int mn = 1 << 30;
        for (int i = 0; i <= na + nb + nc; ++i) {
            int ct1, ct2, ct3, ct4, ct5, ct6;
            ct1 = min(max(0, i), na);
            ct4 = min(max(0, na - i), na);
            ct2 = min(max(0, i - na), nb);
            ct5 = min(max(0, na + nb - i), nb);
            ct3 = min(max(0, i - na - nb), nc);
            ct6 = min(max(0, na + nb + nc - i), nc);
            mn = min(mn, min(ct4 * a + ct5 * b + ct6 * c, max(ct4 + ct5 + ct6, d) * e) + ct1 * a + ct2 * b + ct3 * c);
        }
        cout << mn << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3108
final_rank: 5

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	ll a, b, c, d, e;
	while(true) {
		cin >> a >> b >> c >> d >> e;

		if(a == 0 && b == 0 && c == 0 && d == 0 && e == 0) break;

		ll na, nb, nc;
		cin >> na >> nb >> nc;

		vector<ll> v;
		rep(i, na) v.push_back(a);
		rep(i, nb) v.push_back(b);
		rep(i, nc) v.push_back(c);

		sort(v.begin(), v.end(), greater<ll>());

		ll sum = a * na + b * nb + c * nc;
		ll ans = sum, pre = 0;

		rep(i, v.size()) {
			pre += v[i];
			sum -= v[i];
			if(i >= d-1) {
				ans = min(ans, sum + min(pre, (i + 1) * e));
			} else {
				ans = min(ans, sum + min(pre, d * e));
			}
		}

		cout << ans << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 8656
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> v;
int main(){
  ll a,b,c,d,e;
  ll na,nb,nc;
  while( cin >> a >> b >> c >> d >> e && (a|b|c|d|e) ){
    cin >> na >> nb >> nc;
    v.clear();
    for(int i=0;i<nc;i++) v.push_back(c);
    for(int i=0;i<nb;i++) v.push_back(b);
    for(int i=0;i<na;i++) v.push_back(a);
    ll sum = 0;
    ll reg = na*a + nb*b + nc*c;
    ll res = reg;
    for(int i=0;i<na+nb+nc;i++){      
      sum += v[i];
      if( i+1 >= d ){
        res = min( res, reg - sum + ((ll)i+1)*e );
      } else {
        res = min( res, reg - sum + d * e );
      }
    }
    cout << res << endl;
  }
}
accuracy: 1
time_ms: 50
memory_kb: 5984
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
  int a,b,c,d,e;
  while(cin >> a >> b >> c >> d >> e && a) {
    int na,nb,nc;
    cin >> na >> nb >> nc;
    vector<int> v;
    for(int i=0;i<nc;i++)v.push_back(c);
    for(int i=0;i<nb;i++)v.push_back(b);
    for(int i=0;i<na;i++)v.push_back(a);
    int sum=na*a+nb*b+nc*c;
    int ans=sum,x=0;
    for(int i=0;i<v.size();i++) {
      int y=i+1;
      x+=v[i];
      sum-=v[i];
      if(y>=d) ans=min(ans,y*e+sum);
      else if(x>=d*e) ans=min(ans,d*e+sum);
    }
    cout << ans << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 4240
final_rank: 7

code_snippet: #include <iostream>
using namespace std;

int main() {
	int a, b, c, d, e;
	while(cin >> a >> b >> c >> d >> e, a|b|c|d|e) {
		int na, nb, nc;
		cin >> na >> nb >> nc;
		int sum = na*a + nb*b + nc*c;
		int psum = sum;
		int res = sum;
		for(int i = 0; i < na+nb+nc; i++) {
			if(i<nc)
				psum -= c;
			else if(i<nc+nb)
				psum -= b;
			else
				psum -= a;
			res = min(res ,min(max(i+1,d)*e, sum-psum) + psum);
		}
		cout << res << endl;
	}
}
accuracy: 1
time_ms: 30
memory_kb: 1160
final_rank: 1

code_snippet: #include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
	long long int m[3];
	long long int d, e;
	long long int nn[3];
	while(cin >> m[0] >> m[1] >> m[2] >> d >> e) {
		if (m[0] == 0 && m[1] == 0 && m[2] == 0 && d == 0 && e == 0) {
			break;
		}
		cin >> nn[0] >> nn[1] >> nn[2]; 
		long long int count = m[0]*nn[0]+m[1]*nn[1]+m[2]*nn[2];
		vector<int> v;
		for (int i = 0; i < nn[2]; i++) {
			v.push_back(m[2]);
		}
		for (int i = 0; i < nn[1]; i++) {
			v.push_back(m[1]);
		}
		for (int i = 0; i < nn[0]; i++) {
			v.push_back(m[0]);
		}
		if (d <= nn[2]) {
			count = m[0]*nn[0]+m[1]*nn[1]+e*nn[2];
		} else if (d <= nn[1]+nn[2]){
			count = min(count, min(m[0]*nn[0]+m[1]*(nn[1]-(d-nn[2]))+e*d, m[0]*nn[0]+m[1]*nn[1]+d*e));
		} else if (d <= nn[0]+nn[1]+nn[2]){
			count = min(count, min(m[0]*(nn[0]-(d-nn[2]-nn[1]))+e*d, m[0]*nn[0]+m[1]*nn[1]+d*e));
		} else {
			count = min(count, d*e);
		}
		cout << count << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 4236
final_rank: 6

code_snippet: #include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
	long long int m[3];
	long long int d, e;
	long long int nn[3];
	while(cin >> m[0] >> m[1] >> m[2] >> d >> e) {
		if (m[0] == 0 && m[1] == 0 && m[2] == 0 && d == 0 && e == 0) {
			break;
		}
		cin >> nn[0] >> nn[1] >> nn[2]; 
		long long int count = m[0]*nn[0]+m[1]*nn[1]+m[2]*nn[2];
		vector<int> v;
		for (int i = 0; i < nn[2]; i++) {
			v.push_back(m[2]);
		}
		for (int i = 0; i < nn[1]; i++) {
			v.push_back(m[1]);
		}
		for (int i = 0; i < nn[0]; i++) {
			v.push_back(m[0]);
		}
		for (int i = 0; i < nn[0]+nn[1]+nn[2]; i+=d) {
			if (i + d-1 < nn[0]+nn[1]+nn[2]) {
				long long int counter = 0;
				for (int j = 0; j < d; j++) {
					counter += v[i+j];
				}
				if (counter > d*e) {
					count -= counter;
					count += d*e;
				} else {
					break;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}
accuracy: 0.2
time_ms: 60
memory_kb: 4236
final_rank: 16

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define REP(i,n) for(int i = 0 ; i < n ; ++i)
#define int long long
#define INF 99999999

signed main()
{
	while (1){
		int a, b, c, d, e, na, nb, nc;
		cin >> a >> b >> c >> d >> e >> na >> nb >> nc;

		if (!(a || b || c || d || e))break;

		int ans = (na*a+nb*b+nc*c);

		REP(i, na + nb + nc+1){
			int C = min(i, nc);
			int B = min(i - C, nb);
			int A = min(i - B - C, na);
			int D = max(i, d);
			if (!i)D = 0;
			ans = min(ans, (nc - C)*c + (nb - B)*b + (na - A)*a + D*e);
			//cout << i << ":" << ans << endl;
		}
		cout << ans << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 1156
final_rank: 2

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define REP(i,n) for(int i = 0 ; i < n ; ++i)
#define int long long
#define INF 99999999

bool lc, lb, la;

signed main()
{
	int a, b, c, d, e,na,nb,nc;
	while (1){
		cin >> a >> b >> c >> d >> e >> na >> nb >> nc;

		if (!(a || b || c || d || e))break;

		int ans = INF;

		REP(i, na + nb + nc+1){
			int C = min(i, nc);
			int B = min(i - C, nb);
			int A = min(i - B - C, na);
			int D = max(i, d);
			if (!i)D = 0;
			ans = min(ans, (nc - C)*c + (nb - B)*b + (na - A)*a + D*e);
			//cout << i << ":" << ans << endl;
		}
		cout << ans << endl;
	}
	return 0;
}
accuracy: 0.1
time_ms: 10
memory_kb: 1156
final_rank: 18

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define REP(i,n) for(int i = 0 ; i < n ; ++i)
#define int long long
#define INF 99999999

bool lc, lb, la;

signed main()
{
	int a, b, c, d, e,na,nb,nc;
	while (1){
		cin >> a >> b >> c >> d >> e >> na >> nb >> nc;

		if (!(a || b || c || d || e))break;

		int ans = INF;

		REP(i, na + nb + nc+1){
			int C = min(i, nc);
			int B = min(i - C, nb);
			int A = min(i - B - C, na);
			int D = max(i, d);
			ans = min(ans, (nc - C)*c + (nb - B)*b + (na - A)*a + D*e);
		}
		cout << ans << endl;
	}
	return 0;
}
accuracy: 0.1
time_ms: 10
memory_kb: 1156
final_rank: 18

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
const int INF = (int)1e8;
int main(){
	int a, b, c, d, e, na, nb, nc;

	while (1){
		cin >> a >> b >> c >> d >> e;
		if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0)return 0;
		cin >> na >> nb >> nc;
		int res = na*a+nb*b+nc*c;
		if (nc >= d){
			res=min(res, nc*e + na*a + nb*b);
		}

		for (int i = 0; i <= na + nb + nc;i++){
			int C = max(nc - i, 0);
			int B = max(nb - (i - (nc - C)), 0);
			int A = na - (i - (nc - C) - (nb - B));
			if ((nc - C)*c + (nb - B)*b + (na-A)*a>d*e)
			res = min(res, max(d,i)*e + C*c + B*b + A*a);
		}
		cout << res << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 1160
final_rank: 3

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
const int INF = (int)1e8;
int main(){
	int a, b, c, d, e, na, nb, nc;

	while (1){
		cin >> a >> b >> c >> d >> e;
		if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0)return 0;
		cin >> na >> nb >> nc;
		int res = INF;
		if (nc >= d){
			res=min(res, nc*e + na*a + nb*b);
		}

		for (int i = 0; i <= na + nb + nc;i++){
			int C = max(nc - i, 0);
			int B = max(nb - (i - (nc - C)), 0);
			int A = na - (i - (nc - C) - (nb - B));
			if ((nc - C)*c + (nb - B)*b + (na-A)*a>d*e)
			res = min(res, max(d,i)*e + C*c + B*b + A*a);
		}
		cout << res << endl;
	}

	return 0;
}
accuracy: 0.1
time_ms: 10
memory_kb: 1160
final_rank: 20

code_snippet: #include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;
int main(){
    int a, b, c, d, e;
    int na, nb, nc;
    while(cin >> a >> b >> c >> d >> e >> na >> nb >> nc) {
        LL ans = 0;

        vector<LL> v;
        REP(i, nc) v.push_back(c);
        REP(i, nb) v.push_back(b);
        REP(i, na) v.push_back(a);

        int n = v.size();
        vector<LL>  sum(n + 1);
        REP(i, n) sum[i+1] = sum[i] + v[i];

        for(int i = 0; i < n; i += d) {
            LL num = (i + d <= n ? d : n - i);
            LL x = (i + d <= n) ? (sum[i + d] - sum[i]) : (sum[n] - sum[i]);
            LL y = (i == 0 ? d * e : num * e);
            ans += min(x, y);
        }
        cout << ans << endl;
    }
    return 0;
}
accuracy: 0.2
time_ms: 100
memory_kb: 8920
final_rank: 17