Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Code: THU Packing Puzzle

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

void slove() {
    long long t, h, u;
    long long result = 0;
    cin >> t >> h >> u;
    result += min(t, u) * 4LL;
    long long m = min(t, u);
    t -= m;
    u -= m;
    if (t != 0) {
        if (h != 0) {
            m = min(h, t / 2);
            result += 7LL * min(h, t / 2);
            t -= 2 * m;
            h -= m;
            if (t % 2 == 1 && h > 0) {
                result += 5LL * min(h, 1LL);
                t -= 1;
                h -= 1;
            }
        }
        if (t != 0)
            result += 2LL * (t) + 1;
    }
    result += 3LL * (u + h);
    cout << result << "\n";
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        slove();
    }
    return 0;
}