#include<cstdio>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<map>
#include<vector>
#include<windows.h>
using namespace std;
#define M 15 //避免數組越界
#define clr(a,b) memset(a,b,sizeof a)
using namespace std;
int month;//計劃跨度月份數量
int tot_req;//總共計劃全程需要多少產品
int left_req;//剩下的生產計劃還需要多少產品
int require[M];//計劃每個月的需求量
int pay[M];//每個月公司的總支出
int tmp_req[M];//用來存儲當前最小花費的每個月的需求量
//int now_worker;//現在已有員工數量
int worker_num[M];//每個月員工的數量
int up[M];//每個月員工數量上限
int down[M];//每個月員工數量下限
int work_ability;//員工每天、周、旬內生產產品的數量,0表示天,1表示周,2表示旬
int per_kind;//采用的是天/周/旬哪類單位
int wage;//每個員工每個月的工資
int wage_mon[M];//每個月員工工資總費用
int pro_num[M];//每個月普通生產的總量
int over_fee;//每個員工加班生產1件產品的費用
int over_num[M];//每個月加班生產的總量
int over_mon[M];//每個月加班的總費用
int over_max;//每個員工最多加班生產的產品數
int hire;//雇傭1個新員工的費用
int fire;//解雇1個員工的費用
int hfire[M];//每個月雇傭解雇的總費用
int store_fee;//每月每件多余產品存儲價格
int store_mon[M];//每個月存儲的總費用
int tot_fee=0;//總費用
int store_num[M];//每個月的庫存數量
int ans=0x3f3f3f3f;//最少花費
int cal(){int i;tot_fee=0;for(i=0;i<month;i++){pay[i]=wage_mon[i]+over_mon[i]+store_mon[i]+hfire[i];tot_fee+=pay[i];//總費用等于每個月員工工資總額+加班費總額+存儲費總額+解雇培訓費用總額}return tot_fee;
}
int final_req[M];
int final_worker_num[M];
int final_wage_mon[M];
int final_pro_num[M];
int final_over_num[M];
int final_over_mon[M];
int final_store_mon[M];
int final_store_num[M];
int final_hfire[M];
int final_pay[M];void rec(){int i=0;for(i=0;i<month;i++){final_req[i]=tmp_req[i];final_worker_num[i]=worker_num[i];final_wage_mon[i]=wage_mon[i];final_pro_num[i]=pro_num[i];final_over_num[i]=over_num[i];final_over_mon[i]=over_mon[i];final_store_mon[i]=store_mon[i];final_store_num[i]=store_num[i];final_hfire[i]=hfire[i];final_pay[i]=pay[i];}
}void dfs(int now){//printf("here\n");if(now==month){int t_ans=cal();if(t_ans<ans){ans=t_ans;rec();}return;}int cur_require=require[now]-store_num[now];tmp_req[now]=cur_require;//printf("%d\n",cur_require);int cur_worker_num=worker_num[now];//保存當月初始員工數量up[now]=(int)ceil(1.0*cur_require/work_ability)*2;//員工上限down[now]= (int)ceil(1.0*cur_require/(work_ability+over_max));//printf("%d %d\n",up[now],down[now]);for(worker_num[now]=down[now];worker_num[now]<=up[now];worker_num[now]++){pro_num[now]=worker_num[now]*work_ability;if(cur_require>pro_num[now]){over_num[now]=cur_require-pro_num[now];over_mon[now]=over_num[now]*over_fee;}else{over_num[now]=0;over_mon[now]=0;}worker_num[now+1]=worker_num[now];//下個月員工起始數量等于這個月員工數量wage_mon[now]=worker_num[now]*wage;//該月員工總工資費用if(worker_num[now]>cur_worker_num)hfire[now]=(worker_num[now]-cur_worker_num)*hire;//雇傭員工計算else hfire[now]=(cur_worker_num-worker_num[now])*fire;//解雇員工計算store_num[now+1]=(pro_num[now]+over_num[now]-cur_require);//這個月的需求等于這個月的需求-上個月剩余的庫存store_mon[now]=store_num[now+1]*store_fee;if(store_num[now+1]<0)printf("<0%d\n",store_num[now+1]);dfs(now+1);}
}int check(char *x){int sig=isdigit(x[0]);if(!sig){printf("警告!非法輸入!請輸入正整數!\n");Sleep(10000);exit(0);}else if(atoi(x)<0){printf("警告!非法輸入!請輸入正整數!\n");Sleep(10000);exit(0);}return 1;
}int main(){freopen("D:\\in.txt","r",stdin);scanf("%d",&month);//printf("%d\n",ans);int i,j,k;char str[5][10000];for(i=0;i<month;i++){scanf("%s",str[0]);check(str[0]);require[i]=atoi(str[0]);tot_req+=require[i];}for(i=0;i<5;i++){scanf("%s",str[i]);check(str[i]);}store_num[0]=atoi(str[0]);worker_num[0]=atoi(str[1]);per_kind=atoi(str[2]);wage=atoi(str[3]);work_ability=atoi(str[4]);if(per_kind==0)work_ability*=22;//假設雙休,每月30天else if(per_kind==1)work_ability*=4;else if(per_kind==2)work_ability*=3;for(i=0;i<5;i++){scanf("%s",str[i]);check(str[i]);}over_fee=atoi(str[0]);over_max=atoi(str[1]);hire=atoi(str[2]);fire=atoi(str[3]);store_fee=atoi(str[4]);dfs(0);printf("每個月初始需求量\n");for(i=0;i<month;i++){printf("%d%c",require[i],i==month-1?'\n':'\t');}freopen("D:\\out.txt","w",stdout);printf("總需求量\n");printf("%d\n",tot_req);printf("總費用\n");printf("%d\n",ans);int ttot=0;printf("每個月總支出\n");for(i=0;i<month;i++){printf("%d%c",final_pay[i],i==month-1?'\n':'\t');}printf("每個月實際需求量\n");for(i=0;i<month;i++){printf("%d%c",final_req[i],i==month-1?'\n':'\t');}printf("每個月生產量\n");for(i=0;i<month;i++){printf("%d%c",final_pro_num[i],i==month-1?'\n':'\t');ttot+=final_pro_num[i];}printf("每個月加班生產量\n");for(i=0;i<month;i++){printf("%d%c",final_over_num[i],i==month-1?'\n':'\t');}printf("每個月員工量\n");for(i=0;i<month;i++){printf("%d%c",final_worker_num[i],i==month-1?'\n':'\t');}printf("每個月解雇培訓費\n");for(i=0;i<month;i++){printf("%d%c",final_hfire[i],i==month-1?'\n':'\t');}printf("每個月存儲費\n");for(i=0;i<month;i++){printf("%d%c",final_store_mon[i],i==month-1?'\n':'\t');}printf("每個月員工工資\n");for(i=0;i<month;i++){printf("%d%c",final_wage_mon[i],i==month-1?'\n':'\t');}fclose(stdout);return 0;
}