#include<bits/stdc++.h>
using namespace std;
int n,m,k,ans;
int r1[25],r2[25];
int v1[15],v2[15];
int a[100005][15];
int p[25][15];
bool vis[100005];
struct node
{
int x,id;
}q[15][100005];
bool cmp(node x,node y)
{
return x.x>y.x;
}
void dfs(int x,int s1,int s2)
{
if(x==k+1)
{
int s=0;
for(int i=1;i<=n;++i)
{
int Max=v1[i];
for(int j=1;j<=s1;++j) Max=max(Max,p[r1[j]][i]);
s+=Max;
}
for(int i=1;i<=n;++i)
{
int Max=v2[i];
for(int j=1;j<=s2;++j) Max=max(Max,p[r2[j]][i]);
s+=Max;
}
ans=max(ans,s);
return;
}
r1[s1+1]=x;
dfs(x+1,s1+1,s2);
r2[s2+1]=x;
dfs(x+1,s1,s2+1);
}
int main()
{
freopen("max.in","r",stdin);
freopen("max.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;++i) cin>>v1[i];
for(int i=1;i<=n;++i) cin>>v2[i];
for(int i=1;i<=m;++i)
for(int j=1;j<=n;++j)
{
cin>>a[i][j];
q[j][i]={a[i][j],i};
}
for(int i=1;i<=n;++i) sort(q[i]+1,q[i]+1+m,cmp);
for(int i=1;i<=n;++i)
{
int ok=21/n;
for(int j=1;j<=ok;++j)
if(!vis[q[i][j].id])
{
vis[q[i][j].id]=1;
++k;
for(int r=1;r<=n;++r) p[k][r]=a[q[i][j].id][r];
}
}
dfs(1,0,0);
cout<<ans;
return 0;
}
我的乱搞代码过了