|
| 1 | +/** |
| 2 | + * @file 1174-1004.cpp |
| 3 | + * @author Macesuted (i@macesuted.moe) |
| 4 | + * @date 2025-07-25 |
| 5 | + * |
| 6 | + * @copyright Copyright (c) 2025 |
| 7 | + * |
| 8 | + */ |
| 9 | + |
| 10 | +#include <bits/stdc++.h> |
| 11 | +using namespace std; |
| 12 | + |
| 13 | +int a[15], A[15], B[15], id[15]; |
| 14 | + |
| 15 | +void solve(void) { |
| 16 | + int n = 13; |
| 17 | + for (int i = 1; i <= n; i++) cin >> a[i]; |
| 18 | + |
| 19 | + auto check = [&](int lim) -> bool { |
| 20 | + int sumA = 0, sumB = 0; |
| 21 | + for (int i = 1; i <= n; i++) { |
| 22 | + A[i] = min({a[i] / 3, lim}), sumA += A[i]; |
| 23 | + B[i] = min({a[i] - 3 * A[i], lim - A[i]}), sumB += B[i]; |
| 24 | + } |
| 25 | + if (sumA < lim) return false; |
| 26 | + |
| 27 | + for (int i = 1; i <= n; i++) id[i] = i; |
| 28 | + |
| 29 | + sort(id + 1, id + n + 1, [&](int x, int y) { return (lim - A[x] - B[x]) / 2 > (lim - A[y] - B[y]) / 2; }); |
| 30 | + for (int p = 1; p <= n; p++) { |
| 31 | + int i = id[p], x = min({sumA - lim, (lim - A[i] - B[i]) / 2, A[i]}); |
| 32 | + A[i] -= x, sumA -= x; |
| 33 | + B[i] += 3 * x, sumB += 3 * x; |
| 34 | + } |
| 35 | + |
| 36 | + sort(id + 1, id + n + 1, [&](int x, int y) { return lim - A[x] - B[x] > lim - A[y] - B[y]; }); |
| 37 | + for (int p = 1; p <= n; p++) { |
| 38 | + int i = id[p], x = min({sumA - lim, lim - A[i] - B[i], A[i]}); |
| 39 | + A[i] -= x, sumA -= x; |
| 40 | + B[i] += 2 * x, sumB += 2 * x; |
| 41 | + } |
| 42 | + |
| 43 | + for (int i = 1; i <= n; i++) { |
| 44 | + int x = min(sumA - lim, A[i]); |
| 45 | + A[i] -= x, sumA -= x; |
| 46 | + B[i] += x, sumB += x; |
| 47 | + } |
| 48 | + |
| 49 | + return sumB >= lim; |
| 50 | + }; |
| 51 | + |
| 52 | + int l = 0, r = 1e7; |
| 53 | + while (l + 1 < r) { |
| 54 | + int mid = (l + r) >> 1; |
| 55 | + (check(mid) ? l : r) = mid; |
| 56 | + } |
| 57 | + |
| 58 | + cout << l << endl; |
| 59 | + |
| 60 | + return; |
| 61 | +} |
| 62 | + |
| 63 | +int main() { |
| 64 | + ios::sync_with_stdio(false), cin.tie(nullptr); |
| 65 | + |
| 66 | + int _ = 1; |
| 67 | + cin >> _; |
| 68 | + while (_--) solve(); |
| 69 | + |
| 70 | + return 0; |
| 71 | +} |
0 commit comments