You are playing CSGO.
There are n Main Weapons and m Secondary Weapons in CSGO. You can only choose one Main Weapon and one Secondary Weapon. For each weapon, it has a composite score S.
The higher the composite score of the weapon is, the better for you.
Also each weapon has K performance evaluations x[1], x[2], …, x[K].(range, firing rate, recoil, weight…)
So you shold consider the cooperation of your weapons, you want two weapons that have big difference in each performance, for example, AWP + CZ75 is a good choose, and so do AK47 + Desert Eagle.
All in all, you will evaluate your weapons by this formula.(MW for Main Weapon and SW for Secondary Weapon)
Now you have to choose your best Main Weapon & Secondary Weapon and output the maximum evaluation.
Input
Multiple query.
On the first line, there is a positive integer T, which describe the number of data. Next there are T groups of data.
for each group, the first line have three positive integers n, m, K.
then, the next n line will describe n Main Weapons, K+1 integers each line S, x[1], x[2], …, x[K]
then, the next m line will describe m Secondary Weapons, K+1 integers each line S, x[1], x[2], …, x[K]
There is a blank line before each groups of data.
T<=100, n<=100000, m<=100000, K<=5, 0<=S<=1e9, |x[i]|<=1e9, sum of (n+m)<=300000
Output
Your output should include T lines, for each line, output the maximum evaluation for the corresponding datum.
Sample Input
2 2 2 1 0 233 0 666 0 123 0 456 2 2 1 100 0 1000 100 1000 100 100 0
Sample Output
543 2000
思路:因为需要从主武器和副武器里挑出一个。对于属性的差值,最好的方法肯定是一个最大的减去最小的。
所以可以这样考虑,对于每种属性,它对答案的贡献,要么是加上它,要么是减去它,所以只要枚举每种属性的加减状态就行,
对于主武器的s,和副武器的s,也可以将他们考虑进来,只要将他们的位置错开(这样就可以保证他们不会相减了),将主s设在0位置,副武器s设在1位置即可,最后就是2^(k+2)的枚举。
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+9;
int n,m,k;
ll a[maxn][8],b[maxn][8];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int T;
cin>>T;
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
for(int i=0;i<n;i++)
{
scanf("%lld",&a[i][0]);
for(int j=0;j<k;j++)
{
scanf("%lld",&a[i][j+2]);
}
}
for(int i=0;i<m;i++)
{
scanf("%lld",&b[i][1]);
for(int j=0;j<k;j++)
{
scanf("%lld",&b[i][j+2]);
}
}
int up=1<<(k+2);
ll ans=0;
for(int s=0;s<up;s++)
{
ll maxv1=-1e18,minv1=1e18;
ll maxv2=-1e18,minv2=1e18;
for(int i=0;i<n;i++)
{
ll tmp=0;
for(int t=0;t<k+2;t++)
{
if(s&(1<<t))
{
tmp+=a[i][t];
}
else
{
tmp-=a[i][t];
}
}
maxv1=max(maxv1,tmp);
minv1=min(minv1,tmp);
}
for(int i=0;i<m;i++)
{
ll tmp=0;
for(int t=0;t<(k+2);t++)
{
if(s&(1<<t))
{
tmp+=b[i][t];
}
else
{
tmp-=b[i][t];
}
}
maxv2=max(maxv2,tmp);
minv2=min(minv2,tmp);
}
ans=max(ans,max(maxv1-minv2,maxv2-minv1));
}
printf("%lld\n",ans);
}
}