You are playing CSGO.
There is n Main weapons and M secondary weapons in CSGO. You can be 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 and the better for you.
Also each weapon have 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 both weapons that has big difference in each performance, For example, AWP + CZ75 are a good choose, and so do AK47 + Desert Eagle.
All and you'll evaluate your weapons by this formula. (MW for Main weapon and SW for secondary weapon)
Now there are to choose your best Main weapon & secondary weapon and output the maximum evaluation.
Inputmultiple query.
On the first line, there is a positive integer T, which describe the number of data. Next There is T groups of data.
For each group, the first line has three positive integers n, m, K.
Then, the next n line would describe n Main weapons, k+1 integers each line S, x[1], x[2], ..., x[k]
Then, the next m line would 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
Outputyour output should include T lines, for each line, output of the maximum evaluation for the corresponding datum. Sample Input
22 2 10 2330 6660 1230 4562 2 1100 0 1000 100 1000 100100 0
Sample Output
5432000
Test instructions: There are n kinds of primary weapons, m pairs of weapons, and each weapon has k weights, ask the above-mentioned target formula of the maximum benefit
Thinking Analysis: Consider the nature of the absolute value, the absolute value of a-B is equal to a-a or-a+b, and the title of the K <= 5, obviously here we can binary to enumerate, record the maximum value can be
code example:
#define LL long longconst ll maxn = 1e5+5;ll N, m, K;ll a[maxn][10], b[maxn][10];ll sa[50], sb[50];void init () {ll f = 1; for (ll i = 1; I <= K; i++) f *= 2; memset (SA, 0x8f, sizeof (SA)); memset (SB, 0x8f, sizeof (SB)); printf ("+ +%LLD \ n", sa[0]); for (ll i = 1, i <= N; i++) {for (LL-state = 0, state < F; state++) {ll sum = 0; for (ll j = 0, J < K; J + +) {if (State & (1<<J)) sum + = a[i][j+1]; else sum-= a[i][j+1]; } Sa[state] = max (Sa[state], sum+a[i][0]); }} for (ll i = 1, i <= m; i++) {for (ll state = 0, state < F; state++) {ll sum = 0; for (ll j = 0, J < K; J + +) {if (State & (1<<J)) sum + = b[i][j+1]; else sum-= b[i][j+1]; } Sb[state] = max (Sb[state], sum+b[i][0]); }}}void Solve () {ll num = 1<<k; ll ans = 0x8f; for (ll i = 0; I &lT Num i++) {ll pp = num-1-i; ans = max (ans, sa[i]+sb[pp]); } printf ("%lld\n", ans);} int main () {//freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout); ll T; CIN >> T; while (t--) {scanf ("%lld%lld%lld", &n, &m, &k); for (ll i = 1; I <= n; i++) {for (ll j = 0; J <= K; j + +) {scanf ("%lld", &a[i][j]); }} for (ll i = 1, i <= m; i++) {for (ll j = 0; J <= K; j + +) {scanf ("%l LD ", &b[i][j]); }} init (); Solve (); } return 0;}
State compression Hdu #10