In an online game, “Lead of Wisdom” is a place where the lucky player can randomly get powerful items.
There are k types of items, a player can wear at most one item for each type. For the i-th item, it has four attributes ai,bi,ci and di. Assume the set of items that the player wearing is S, the damage rate of the player DMG can be calculated by the formula:
DMG=(100+∑i∈Sai)(100+∑i∈Sbi)(100+∑i∈Sci)(100+∑i∈Sdi)
Little Q has got n items from “Lead of Wisdom”, please write a program to help him select which items to wear such that the value of DMG is maximized.
Input
The first line of the input contains a single integer T (1≤T≤10), the number of test cases.
For each case, the first line of the input contains two integers n and k (1≤n,k≤50), denoting the number of items and the number of item types.
Each of the following n lines contains five integers ti,ai,bi,ci and di (1≤ti≤k, 0≤ai,bi,ci,di≤100), denoting an item of type ti whose attributes are ai,bi,ci and di.
Output
For each test case, output a single line containing an integer, the maximum value of DMG.
Sample Input
1
6 4
1 17 25 10 0
2 0 0 25 14
4 17 0 21 0
1 5 22 0 10
2 0 16 20 0
4 37 0 0 0
Sample Output
297882000
int vis[55];
ll ans=0;
int t;
int no[55][55][4];
int nex[55];
void sol(int pos,int sumA,int sumB,int sumC,int sumD) {
if(pos==k+1) {
ll sum=1ll*sumA*sumB*sumC*sumD;
ans=max(ans,sum);
return;
}
int num=vis[pos];
if(!num) {
sol(nex[pos],sumA,sumB,sumC,sumD);
return ;
}
for(int i=1; i<=num; i++)
sol(pos+1,no[pos][i][0]+sumA,no[pos][i][1]+sumB,no[pos][i][2]+sumC,no[pos][i][3]+sumD);
}
int main() {
int T=read();
while(T--) {
ans=0;
memset(vis,0,sizeof(vis));
n=read();
k=read();
for(int i=1; i<=n; i++) {
t=read();
vis[t]++;
no[t][vis[t]][0]=read();
no[t][vis[t]][1]=read();
no[t][vis[t]][2]=read();
no[t][vis[t]][3]=read();
}
//sort(no+1,no+n+1,cmp);
int x=k+1;
for(int i=k; i>=1; i--) {
nex[i]=x;
if(vis[i]) {
x=i;
}
}
sol(1,100,100,100,100);
printf("%lld\n",ans);
}
return 0;
}