1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
2 #include <cstdio>//sprintf islower isupper
3 #include <cstdlib>//malloc exit strcat itoa system("cls")
4 #include <iostream>//pair
5 #include <fstream>//freopen("C:\Users\13606\Desktop\草稿.txt","r",stdin);
6 #include <bitset>
7 //#include <map>
8 //#include<unordered_map>
9 #include <vector>
10 #include <stack>
11 #include <set>
12 #include <string.h>//strstr substr
13 #include <string>
14 #include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
15 #include <cmath>
16 #include <deque>
17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
18 #include <vector>//emplace_back
19 //#include <math.h>
20 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
21 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
22 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
23 //******************
24 int abss(int a);
25 int lowbit(int n);
26 int Del_bit_1(int n);
27 int maxx(int a,int b);
28 int minn(int a,int b);
29 double fabss(double a);
30 void swapp(int &a,int &b);
31 clock_t __STRAT,__END;
32 double __TOTALTIME;
33 void _MS(){__STRAT=clock();}
34 void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
35 //***********************
36 #define rint register int
37 #define fo(a,b,c) for(rint a=b;a<=c;++a)
38 #define fr(a,b,c) for(rint a=b;a>=c;--a)
39 #define mem(a,b) memset(a,b,sizeof(a))
40 #define pr printf
41 #define sc scanf
42 #define ls rt<<1
43 #define rs rt<<1|1
44 typedef long long ll;
45 const double E=2.718281828;
46 const double PI=acos(-1.0);
47 //const ll INF=(1LL<<60);
48 const int inf=(1<<30);
49 const double ESP=1e-9;
50 const int mod=(int)1e9+7;
51 const int N=(int)1e6+10;
52
53 int dp[N][30];
54 int a[N],b[N];
55
56 int main()
57 {
58 int l,n;
59 while(~sc("%d%d",&l,&n))
60 {
61 for(int i=1;i<=l;++i)
62 {
63 int t;
64 sc("%d",&t);
65 for(int j=0;j<n;++j)
66 a[i+j*l]=t;
67 }
68 for(int i=1;i<=l;++i)
69 {
70 int t;
71 sc("%d",&t);
72 for(int j=0;j<n;++j)
73 b[i+j*l]=t;
74 }
75 int tot=l*n;
76 for(int i=0;i<=tot;++i)
77 for(int j=0;j<=20;++j)
78 dp[i][j]=inf;
79 dp[0][0]=0;
80
81 for(int i=1;i<=tot;++i)
82 {
83 for(int j=0;j<=14;++j)
84 {
85 if(j!=0&&dp[i-1][j-1]!=inf)
86 dp[i][j]=dp[i-1][j-1]+a[i];//不加速
87 if(dp[i-1][14]!=inf)
88 dp[i][10]=min(dp[i][10],dp[i-1][14]+a[i]);
89 if(j<=9)
90 dp[i][j]=min(dp[i][j],dp[i-1][j+5]+b[i]);//加速
91 }
92 }
93 /* for(int i=0;i<=tot;++i)
94 pr("%5d%c",i,"
"[i==tot]);
95 for(int j=0;j<=10;++j)
96 {
97 for(int i=0;i<=tot;++i)
98 pr("%5d%c",dp[i][j],"
"[i==tot]);
99 }*/
100 int ans=inf;
101 for(int i=0;i<=14;++i)
102 ans=min(ans,dp[tot][i]);
103 pr("%d
",ans);
104 }
105 return 0;
106 }
107
108 /**************************************************************************************/
109
110 int maxx(int a,int b)
111 {
112 return a>b?a:b;
113 }
114
115 void swapp(int &a,int &b)
116 {
117 a^=b^=a^=b;
118 }
119
120 int lowbit(int n)
121 {
122 return n&(-n);
123 }
124
125 int Del_bit_1(int n)
126 {
127 return n&(n-1);
128 }
129
130 int abss(int a)
131 {
132 return a>0?a:-a;
133 }
134
135 double fabss(double a)
136 {
137 return a>0?a:-a;
138 }
139
140 int minn(int a,int b)
141 {
142 return a<b?a:b;
143 }