Problem:
Discounts of Buckwheat
Aizu is famous for its buckwheat. There are many people who make buckwheat noodles by themselves.
One day, you went shopping to buy buckwheat flour. You can visit three shops, A, B and C. The amount in a bag and its unit price for each shop is determined by the follows table. Note that it is discounted when you buy buckwheat flour in several bags.
Shop A
Shop B
Shop C
Amount in a bag
200g
300g
500g
Unit price for a bag (nominal cost)
380 yen
550 yen
850 yen
Discounted units
per 5 bags
per 4 bags
per 3 bags
Discount rate
reduced by 20 %
reduced by 15 %
reduced by 12 %
For example, when you buy 12 bags of flour at shop A, the price is reduced by 20 % for 10 bags, but not for other 2 bags. So, the total amount shall be (380 × 10) × 0.8 + 380 × 2 = 3,800 yen.
Write a program which reads the amount of flour, and prints the lowest cost to buy them. Note that you should buy the flour of exactly the same amount as the given input.
Input
The input consists of multiple datasets. For each dataset, an integer
a
(500 ≤
a
≤ 5000,
a
is divisible by 100) which represents the amount of flour is given in a line.
The input ends with a line including a zero. Your program should not process for the terminal symbol. The number of datasets does not exceed 50.
Output
For each dataset, print an integer which represents the lowest cost.
Sample Input
500
2200
0
Output for the Sample Input
850
3390

Submitted solutions:

code_snippet: #include <iostream>
#include <climits>

void init_nums(int nums[])
{
	nums[0] = nums[1] = nums[2] = 0;
}

int cost(int nums[])
{
	int A = nums[0];
	int B = nums[1];
	int C = nums[2];
	
	int qA = A / 5;
	int rA = A % 5;
	int qB = B / 4;
	int rB = B % 4;
	int qC = C / 3;
	int rC = C % 3;
	
	return 1520 * qA + 380 * rA + 1870 * qB + 550 * rB + 2244 * qC + 850 * rC;
}

int minCost(int a, int nums[])
{
	if (a==0) return cost(nums);
	
	int res = INT_MAX;
	
	if (a>=500) {
		nums[2]++; 
		res = std::min(res, minCost(a-500, nums));
		nums[2]--;
	}
	if (a>=300) {
		nums[1]++;
		res = std::min(res, minCost(a-300, nums));
		nums[1]--;
	}
	if (a>=200) {
		nums[0]++;
		res = std::min(res, minCost(a-200, nums));
		nums[0]--;
	}
	
	return res;
}

int main()
{
	int a;
	int nums[3];
	while (true) {
		std::cin >> a;
		if (a == 0) break;
		init_nums(nums);
		std::cout << minCost(a, nums) << std::endl;
	}
	return 0;
}
accuracy: 1
time_ms: 590
memory_kb: 3100
final_rank: 10

code_snippet: #include<iostream>
#include<algorithm>
#define INF (1<<26)
using namespace std;
 
int n,ans;
int checkA(int);
int checkB(int);
int checkC(int);
 
int main(){
  while(cin>>n){
    if(n==0)break;
 
    ans=INF;
 
    for(int i=0;i<100;i++){
      for(int j=0;j<100;j++){
    for(int k=0;k<100;k++){
      //if(i==5&&j==0&&k==0)cout<<checkA(i)<<' '<<checkB(j)<<' '<<checkC(k)<<endl;
      if( i*200+j*300+k*500 == n){
        ans=min(ans,checkA(i)+checkB(j)+checkC(k));
      }
 
    }
      }
    }    
    cout<<ans<<endl;
  }
  return 0;
}
int checkA(int cnt){
 
  int x = cnt - (cnt % 5), y = cnt % 5;
  return x*304 + y*380;
}
 
int checkB(int cnt){
 
  int x = cnt - (cnt % 4), y = cnt % 4;
  x/=4;
  return x*1870 + y*550;
}
 
int checkC(int cnt){
 
  int x = cnt - (cnt % 3), y = cnt % 3;
  return x*748 + y*850;
}
accuracy: 1
time_ms: 20
memory_kb: 3056
final_rank: 8

code_snippet: #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return b.second > a.second;
    }
    return a.first < b.first;
}

int arr[200010];
int a[200010], b[200010];

int GCD(int a, int b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    return GCD(b, a % b);
}

int dp[55][30][30][30];

int rec(int sum, int cost, int a, int b, int c)
{
    if (sum == 0)
    {
        return cost;
    }
    if (sum < 0)
    {
        return INT_MAX;
    }
    if (dp[sum][a][b][c] != INT_MAX)
        return dp[sum][a][b][c];

    int res = INT_MAX;

    if ((a + 1) % 5 == 0)
    {
        res = min(res, rec(sum - 2, cost - 380 * 4 + 380 * 5 * 0.80, a + 1, b, c));
    }
    else
    {
        res = min(res, rec(sum - 2, cost + 380, a + 1, b, c));
    }

    if ((b + 1) % 4 == 0)
    {
        res = min(res, rec(sum - 3, cost - 550 * 3 + 550 * 4 * 0.85, a, b + 1, c));
    }
    else
    {
        res = min(res, rec(sum - 3, cost + 550, a, b + 1, c));
    }

    if ((c + 1) % 3 == 0)
    {
        res = min(res, rec(sum - 5, cost - 850 * 2 + 850 * 3 * 0.88, a, b, c + 1));
    }
    else
    {
        res = min(res, rec(sum - 5, cost + 850, a, b, c + 1));
    }

    return dp[sum][a][b][c] = min(dp[sum][a][b][c], res);
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    int n;
    while (cin >> n)
    {
        if (n == 0)
        {
            break;
        }

        for (int i = 0; i < 55; ++i)
        {
            for (int j = 0; j < 30; ++j)
            {
                for (int k = 0; k < 30; ++k)
                {
                    for (int l = 0; l < 30; ++l)
                    {
                        dp[i][j][k][l] = INT_MAX;
                    }
                }
            }
        }
        n /= 100;
        cout << rec(n, 0, 0, 0, 0) << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 8896
final_rank: 12

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout<<fixed<<setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

ll n, ans;
void dfs(ll a, ll b, ll c)
{
	ll g = a * 200 + b * 300 + c * 500;
	if (g == n) {
		ll y = (a - a % 5) * 304 + a % 5 * 380 + (b - b % 4) / 4 * 1870 + b % 4 * 550 + (c - c % 3) * 748 + c % 3 * 850;
		ans = min(ans, y);
	} else if (g < n) {
		dfs(a + 1, b, c);
		dfs(a, b + 1, c);
		dfs(a, b, c + 1);
	}
}
signed main()
{
	while ((n = in()) != 0) {
		ans = INFLL;
		dfs(0, 0, 0);
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 990
memory_kb: 2988
final_rank: 15

code_snippet: #include <iostream>
using namespace	std;
int main(){
  for(int n;cin>>n&&n;){
    int r=1e9;
    for(int c0=0;c0<=25;c0++)
      for(int c1=0;c1<=16;c1++)
        for(int c2=0;c2<=10;c2++)
          for(int c3=0;c3<=5;c3++)
            for(int c4=0;c4<=4;c4++)
              for(int c5=0;c5<=3;c5++)
                if(n==c0*200+c1*300+c2*500+c3*1000+c4*1200+c5*1500) r=min(r,c0*380+c1*550+c2*850+c3*1520+c4*1870+c5*2244);
    cout<<r<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3100
final_rank: 7

code_snippet: #include <stdio.h>

int main() {
  int stack[50], sp = 0, n, i, sum;
  while (scanf("%d", &stack[sp++]) != EOF)
    ;
  for (i = 0; i < sp; i++) {
    int ans = 1000000;
    n = stack[i];
    if (n == 0)
      break;
    for (int a = 0; a <= 50; a++) {
      for (int b = 0; b <= 50; b++) {
        for (int c = 0; c <= 50; c++) {
          sum = (380 * (5 * (a / 5))) * 0.8 + (a % 5) * 380;
          sum += (550 * (4 * (b / 4))) * 0.85 + (b % 4) * 550;
          sum += (850 * (3 * (c / 3))) * 0.88 + (c % 3) * 850;
          if (a * 200 + b * 300 + c * 500 == n) {
            if (sum < ans)
              ans = sum;
          }
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2564
final_rank: 5

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

using namespace std;

int dfs(int a, int b, int c, int n);
int calcAmount(int a, int b, int c);
int calcValue(int a, int b, int c);

int main() {
    int a, b, c;

    int n;

    while (cin >> n) {
        if(n == 0) break;
        a = 0; b = 0; c = 0;
        
        cout << dfs(a, b, c, n) << endl;
    }

        return 0;
}

int dfs(int a, int b, int c, int n) {
    int amount = calcAmount(a, b, c);

    if(amount == n) {
        return calcValue(a, b, c);
    } else if(amount > n) {
        return INT_MAX;
    } else {
        return min(min(dfs(a+1, b, c, n), dfs(a, b+1, c, n)), dfs(a, b, c+1, n));
    }
}

int calcAmount(int a, int b, int c) {
    return a*200 + b*300 + c*500;
}

int calcValue(int a, int b, int c) {
    a = 380*(a/5)*4 + 380*(a%5);
    b = 550*(b/4)*17/5 + 550*(b%4);
    c = 850*(c/3)*264/100 + 850*(c%3);

    return a+b+c;
}
accuracy: 1
time_ms: 900
memory_kb: 2972
final_rank: 13

code_snippet: #include <iostream>
#define MAX_P 1000000
using namespace std;
int g;
int minx=0;
void price(int a,int b,int c){
	if(a/5*1520+a%5*380+b/4*1870+b%4*550+c/3*2244+c%3*850<minx)
		minx=a/5*1520+a%5*380+b/4*1870+b%4*550+c/3*2244+c%3*850;
	return; 
}

void shop(int g,int a,int b,int c){
	if(g==0){
		price(a,b,c);
		return;
	}else if(g<0){
		return;
	}
	shop(g-200,a+1,b,c);
	shop(g-300,a,b+1,c);
	shop(g-500,a,b,c+1);
	return;
}

int main(){
	while(1){
		cin >> g;
		if(g==0)break;
		minx=MAX_P;	
		shop(g,0,0,0);
		cout << minx << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 930
memory_kb: 3084
final_rank: 14

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

#define MAX_N 10000

int dp[4][10000], cnt, cnt2;
int v[3] = { 2,3,5 }, w[3] = { 380,550,850 }, x[3] = { 5,4,3 }, y[3] = { 20,15,12 };

int main() {
	memset(dp, 127, sizeof(dp));
	dp[0][0] = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < MAX_N; j++) {
			cnt = 0; cnt2 = 0;
			for (int k = j; k < MAX_N; k += v[i]) {
				dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + cnt);
				cnt += w[i];
				cnt2++;
				if (cnt2%x[i] == 0) {
					cnt -= (w[i] * x[i])*y[i] / 100;
				}
			}
		}
	}
	while (true) {
		int n;
		cin >> n;
		if (n == 0) { break; }
		cout << dp[3][n / 100] << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 1324
final_rank: 6

code_snippet: #include <iostream>

using namespace std;

int soba[][2] = {
	{200, 380},
	{300, 550},
	{500, 850}
};

int main() {
	int n, m = 5000 * 500;
	cin >> n;
	if (n == 0){
		return 0;
	}
	for (int i = n / soba[2][0] + 100; i >= 0; i--) {
		for (int j = n / soba[1][0] + 100; j >= 0; j--) {
			for (int k = n / soba[0][0] + 100; k >= 0; k--) {
				int w = i * soba[2][0] + j * soba[1][0] + k * soba[0][0];
				if (w == n) {
					int p = (i / 3 * 3 * soba[2][1] * 0.88) + (i % 3 * soba[2][1]) + (j / 4 * 4 * soba[1][1] * 0.85) + (j % 4 * soba[1][1]) + (k / 5 * 5 * soba[0][1] * 0.8) + (k % 5 * soba[0][1]);
					if (p < m) {
						m = p;
					}
				}
			}
		}
	}
	cout << m << endl;
	return main();
}
accuracy: 1
time_ms: 40
memory_kb: 1164
final_rank: 3

code_snippet: #include <iostream>
using namespace std;

int kona, minm;

void search(int k, int a, int b, int c){
  if(k <= 0){
    int am = (a / 5) * 5 * 380 * 0.8 + (a % 5) * 380;
    int bm = (b / 4) * 4 * 550 * 0.85 + (b % 4) * 550;
    int cm = (c / 3) * 3 * 850 * 0.88 + (c % 3) * 850;
    int all = am + bm + cm;
    if(all < minm) minm = all;
    return;
  }

  if(k >= 200) search(k - 200, a + 1, b, c);
  if(k >= 300) search(k - 300, a, b + 1, c);
  if(k >= 500) search(k - 500, a, b, c + 1);
}

int main(void){
  while(cin >> kona && kona != 0){
    minm = 100000000;
    search(kona, 0, 0, 0);
    cout << minm << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 970
memory_kb: 1160
final_rank: 11

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

using namespace std;

/*
200 380
300 550
500 850
1000 1520
1200 1870
1500 2244
*/

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector< vector<int> > dp(5000+1, vector<int>(6+1, 1000000));
		int w[6] = {200, 300, 500, 1000, 1200, 1500};
		int v[6] = {380, 550, 850, 1520, 1870, 2244};
		dp[0][0] = 0;
		dp[200][1] = 380;
		dp[300][2] = 550;
		dp[500][3] = 850;
		dp[1000][4] = 1520;
		dp[1200][5] = 1870;
		dp[1500][6] = 2244;
		for (int i = 0; i < 6; i++) {
			for (int j = 0; j <= n; j+=100) {
				if (j < w[i]) {
					dp[j][i+1] = dp[j][i];
				} else {
					dp[j][i+1] = min(dp[j][i], dp[j-w[i]][i+1]+v[i]);
				}
			}
		}
		cout << dp[n][6] << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1528
final_rank: 4

code_snippet: #include<iostream>
#include<map>
using namespace std;

int main(){

	int w, val[50], cnt[6], v;

	map<char, int> fix, dsc, weight;
	
	weight.insert(make_pair('A', 200));
	weight.insert(make_pair('B', 300));
	weight.insert(make_pair('C', 500));
	
	fix.insert(make_pair('A', 380));
	fix.insert(make_pair('B', 550));
	fix.insert(make_pair('C', 850));
	
	dsc.insert(make_pair('A', 1520));
	dsc.insert(make_pair('B', 1870));
	dsc.insert(make_pair('C', 2244));
	
	fill(val, val+50, 9500);
	fill(cnt, cnt+6, 0);

	for(int cnt_fA=0; cnt_fA<=25; cnt_fA++){
		for(int cnt_fB=0; cnt_fB<=16; cnt_fB++){
			for(int cnt_fC=0; cnt_fC<=10; cnt_fC++){
				for(int cnt_dA=0; cnt_dA<=5; cnt_dA++){
					for(int cnt_dB=0; cnt_dB<=4; cnt_dB++){
						for(int cnt_dC=0; cnt_dC<=3; cnt_dC++){
							w = weight['A']*(cnt_fA + 5*cnt_dA) + weight['B']*(cnt_fB + 4*cnt_dB) + weight['C']*(cnt_fC + 3*cnt_dC);
							if(w <= 5000){
								v = fix['A']*cnt_fA + fix['B']*cnt_fB + fix['C']*cnt_fC + dsc['A']*cnt_dA + dsc['B']*cnt_dB + dsc['C']*cnt_dC;
								val[w/100] = min(val[w/100], v);
							}
						}
					}
				}
			}
		}
	}
	
	while(cin >> w){
		if(w == 0) break;
		cout << val[w / 100] << endl;
	}

	return 0;

}
accuracy: 1
time_ms: 10
memory_kb: 1196
final_rank: 1

code_snippet: #include<iostream>
#include<algorithm>
#define INF (1<<26)
using namespace std;

int n,ans;
int checkA(int);
int checkB(int);
int checkC(int);

int main(){
  while(cin>>n){
    if(n==0)break;

    ans=INF;

    for(int i=0;i<100;i++){
      for(int j=0;j<100;j++){
	for(int k=0;k<100;k++){
	  //if(i==5&&j==0&&k==0)cout<<checkA(i)<<' '<<checkB(j)<<' '<<checkC(k)<<endl;
	  if( i*200+j*300+k*500 == n){
	    ans=min(ans,checkA(i)+checkB(j)+checkC(k));
	  }

	}
      }
    }    
    cout<<ans<<endl;
  }
  return 0;
}
int checkA(int cnt){

  int x = cnt - (cnt % 5), y = cnt % 5;
  return x*304 + y*380;
}

int checkB(int cnt){

  int x = cnt - (cnt % 4), y = cnt % 4;
  x/=4;
  return x*1870 + y*550;
}

int checkC(int cnt){

  int x = cnt - (cnt % 3), y = cnt % 3;
  return x*748 + y*850;
}
accuracy: 1
time_ms: 40
memory_kb: 1160
final_rank: 2

code_snippet: #include <iostream>

using namespace std;

int minP = 999999999;
void DFS(int w, int p, int a, int b, int c)
{
	if(w == 0)
	{
		if(minP > p)
		{
			minP = p;
		}
	}
	if(w - 200 >= 0)
	{
		if(a + 1 < 5)
		{
			DFS(w - 200, p + 380, a + 1, b, c);
		}
		else
		{
			DFS(w - 200, p, 0, b, c);
		}
	}
	if(w - 300 >= 0)
	{
		if(b + 1 < 4)
		{
			DFS(w - 300, p + 550, a, b + 1, c);
		}
		else
		{
			DFS(w - 300, p + 220, a, 0, c);
		}
	}
	if(w - 500 >= 0)
	{
		if(c + 1 < 3)
		{
			DFS(w - 500, p + 850, a, b, c + 1);
		}
		else
		{
			DFS(w - 500, p + 544, a, b, 0);
		}
	}
	return;
}

void solve()
{
	int w;
	while(cin >> w, w)
	{
		minP = 999999999;
		DFS(w, 0, 0, 0, 0);
		cout << minP << endl;
	}
}

int main()
{
	solve();
	return(0);
}
accuracy: 1
time_ms: 690
memory_kb: 1156
final_rank: 9