Code:
#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
#define maxk 7
#define INF 2139062143
int n,k,c[maxk],w[maxn];
struct node {
int a[maxk];
}e[maxn];
inline void init_() {
freopen("a.txt","r",stdin);
}
inline int read_() {
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
x=(x<<1)+(x<<3)+c-'0';
c=getchar();
}
return x*f;
}
inline bool cmp_(node aa,node bb) {
return aa.a[k] > bb.a[k];
}
inline void work_() {
sort(e+1,e+n+1,cmp_);
int ans=-INF;
for(int i=1;i<=n;++i) {
for(int j=1;j<=k;++j) {
e[i].a[j]*=c[j];
}
}
for(int s=0;s < ( 1<< (k-1) ) ;++s) {
for(int i=1;i<=n;++i) {
w[i]=0;
for(int j=1;j<=(k-1);++j) {
if( s & ( 1<<(j-1) ) ) w[i]-=e[i].a[j];
else w[i]+=e[i].a[j];
}
w[i]+=e[i].a[k];
}
int mind=INF;
for(int i=1;i<=n;++i) {
ans=max(ans,w[i]-mind);
mind=min(mind,w[i]);
}
}
printf("%d",ans);
}
void readda_() {
n=read_();k=read_();
for(int i=1;i<=k;++i) {
c[i]=read_();
}
for(int i=1;i<=n;++i) {
for(int j=1;j<=k;++j) {
e[i].a[j]=read_();
}
}
}
int main() {
readda_();
work_();
return 0;
}