topic
answer
Title
Given two arrays a
, and b
, is known by 0
, 1
, 2
composition, seeking in the title can be given configuration under maximum equations Σ 1 <= i <= nci \ sum_ {1 <= i <= n} c_i∑1<=i<=nci.
answer
Try to make the a
middle 2
and the b
middle 1
in the same position, and the b
middle 2
and the a
middle 0
and 2
in the same position.
AC code
It can be simplified here.
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ull unsigned long long
#define ll long long
#define rep(i, x, y) for(int i=x;i<=y;i++)
#define mms(x, n) memset(x, n, sizeof(x))
#define mmc(A, tree) memcpy(A, tree, sizeof(tree))
#define eps (1e-8)
#define PI (acos(-1.0))
#define INF (0x3f3f3f3f)
#define mod (ull)(1e9+7)
typedef pair<int, int> P;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int T;
scanf("%d", &T);
while (T--) {
ll x1, x2, y1, y2, z1, z2;
scanf("%lld%lld%lld%lld%lld%lld", &x1, &y1, &z1, &x2, &y2, &z2);
ll sum = 0;
if (z1 >= y2) {
z1 -= y2;
sum += y2 * 2;
y2 = 0;
} else {
y2 -= z1;
sum += z1 * 2;
z1 = 0;
}
if (z2 >= z1) {
z2 -= z1;
z1 = 0;
if (z2 >= x1) {
z2 -= x1;
x1 = 0;
sum -= min(y1, z2) * 2;
}
}
printf("%lld\n", sum);
}
return 0;
}
postscript
WA has QAQ many times, the logic is not very strict, keep working hard!