結果

問題 No.1823 Tricolor Dango
ユーザー NalimeNalime
提出日時 2022-03-04 19:45:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,002 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 205,360 KB
実行使用メモリ 4,588 KB
最終ジャッジ日時 2023-09-25 21:07:48
合計ジャッジ時間 5,626 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 14 ms
4,380 KB
testcase_08 AC 13 ms
4,376 KB
testcase_09 AC 15 ms
4,504 KB
testcase_10 AC 13 ms
4,380 KB
testcase_11 AC 12 ms
4,376 KB
testcase_12 AC 10 ms
4,384 KB
testcase_13 AC 13 ms
4,380 KB
testcase_14 AC 12 ms
4,380 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 10 ms
4,380 KB
testcase_18 AC 19 ms
4,380 KB
testcase_19 AC 46 ms
4,588 KB
testcase_20 AC 18 ms
4,380 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define SZ(a)   int(size(a))
#define ALL(a)  begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)

using ll = long long;
using i128 = __int128_t;
using ld = long double;
using pii = pair<int, int>;

bool solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (auto &x : a) cin >> x;

    ll sum = accumulate(ALL(a), 0LL);
    if (sum % 3) return false;

    sort(RALL(a));

    auto f = [&](ll d) {
        ll cnt = 0;
        for (int i = 2; i < n; i++) {
            cnt += max(a[i] - (a[1] - d - 1), 0LL);
        }
        return cnt >= d;
    };

    ll l = -1, r = a[1];
    while (l + 1 < r) {
        ll m = (l + r) / 2;
        if (f(m)) l = m;
        else r = m;
    }
    if (l == 0) return false;

    return 2 * (a[0] - l) <= sum - 3 * l;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int tcs = 1;
    cin >> tcs;
    for (int tc = 1; tc <= tcs; tc++) {
        cout << (solve() ? "Yes" : "No") << '\n';
    }
}
0