Codeforces 1401B Ternary Sequence

topic

1401B

answer

Title

Given two arrays a, and b, is known by 0, 1, 2composition, seeking in the title can be given configuration under maximum equations Σ 1 <= i <= nci \ sum_ {1 <= i <= n} c_i1<=i<=nci.

answer

Try to make the amiddle 2and the bmiddle 1in the same position, and the bmiddle 2and the amiddle 0and 2in 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!

Guess you like

Origin blog.csdn.net/qq_45934120/article/details/108609051