1 #include<cstdio>
2 #include<iostream>
3 #include<cmath>
4 #include<cassert>
5 #include<cstring>
6 #include<algorithm>
7 #define maxn 105
8 #define maxm 5555
9 #define inf 1E100
10 #define eps 1E-7
11 using namespace std;
12 char ch;
13 bool ok;
14 void read(int &x){
15 for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch==‘-‘) ok=1;
16 for (x=0;isdigit(ch);x=x*10+ch-‘0‘,ch=getchar());
17 if (ok) x=-x;
18 }
19 int n,m,sum,x,dps[maxn];
20 struct flow{
21 int s,t,tot,now[maxn],son[maxm],pre[maxm];
22 double val[maxm];
23 int dis[maxn],head,tail,list[maxn];
24 bool bo[maxn];
25 void init(int n){s=0,t=n+1,tot=1,memset(now,0,sizeof(now));}
26 void put(int a,int b,double c){pre[++tot]=now[a],now[a]=tot,son[tot]=b,val[tot]=c;}
27 void add(int a,int b,double c){put(a,b,c),put(b,a,0);}
28 bool bfs(){
29 memset(bo,0,sizeof(bo));
30 head=0,tail=1,list[1]=s,dis[s]=0,bo[s]=1;
31 while (head<tail){
32 int u=list[++head];
33 for (int p=now[u],v=son[p];p;p=pre[p],v=son[p])
34 if (val[p]>eps&&!bo[v]) dis[v]=dis[u]+1,bo[v]=1,list[++tail]=v;
35 }
36 return bo[t];
37 }
38 double dfs(int u,double rest){
39 if (u==t) return rest;
40 double ans=0;
41 for (int p=now[u],v=son[p];p&&rest;p=pre[p],v=son[p])
42 if (val[p]>eps&&dis[v]==dis[u]+1){
43 double d=dfs(v,min(rest,val[p]));
44 val[p]-=d,val[p^1]+=d,rest-=d,ans+=d;
45 }
46 if (ans<eps) dis[u]=-1;
47 return ans;
48 }
49 double dinic(){
50 double ans=0;
51 while (bfs()) ans+=dfs(s,inf);
52 return ans;
53 }
54 }f,tmp;
55 void prepare(double lim){
56 f=tmp;
57 for (int i=1;i<=m;i++) f.add(0,i,dps[i]*lim);
58 }
59 int main(){
60 read(n),read(m),f.init(n+m);
61 for (int i=1;i<=n;i++) read(x),sum+=x,f.add(i+m,n+m+1,x);
62 for (int i=1;i<=m;i++) read(dps[i]);
63 for (int i=1;i<=m;i++) for (int j=1;j<=n;j++){
64 read(x);
65 if (x) f.add(i,j+m,inf);
66 }
67 tmp=f;
68 double l=0,r=5E6,mid;
69 while (r-l>eps){
70 mid=(l+r)/2;
71 prepare(mid);
72 if (abs(f.dinic()-sum)<=eps) r=mid;
73 else l=mid;
74 }
75 printf("%.7f\n",l);
76 return 0;
77 }