結果

問題 No.1341 真ん中を入れ替えて門松列
ユーザー MisterMister
提出日時 2021-01-15 22:50:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 736 ms / 2,000 ms
コード長 1,576 bytes
コンパイル時間 1,035 ms
コンパイル使用メモリ 95,756 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 18:07:28
合計ジャッジ時間 8,592 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 464 ms
4,380 KB
testcase_08 AC 324 ms
4,376 KB
testcase_09 AC 345 ms
4,380 KB
testcase_10 AC 620 ms
4,380 KB
testcase_11 AC 623 ms
4,376 KB
testcase_12 AC 578 ms
4,376 KB
testcase_13 AC 652 ms
4,380 KB
testcase_14 AC 736 ms
4,376 KB
testcase_15 AC 654 ms
4,376 KB
testcase_16 AC 647 ms
4,376 KB
testcase_17 AC 658 ms
4,376 KB
testcase_18 AC 324 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;
using lint = long long;

void solve() {
    int n;
    lint m;
    cin >> n >> m;

    vector<pair<lint, lint>> ps(n);
    vector<lint> bs(n);
    for (int i = 0; i < n; ++i) {
        auto& [a, c] = ps[i];
        auto& b = bs[i];
        cin >> a >> b >> c;
        if (a > c) swap(a, c);
    }

    sort(bs.begin(), bs.end());
    sort(ps.begin(), ps.end(),
         [](auto p, auto q) { return p.second > q.second; });

    lint score = -1;
    for (int s = 0; s <= n; ++s) {
        lint sum = 0;

        multiset<lint> ss(bs.begin(), bs.begin() + s);
        vector<pair<lint, lint>> qs;
        for (int i = 0; i < n; ++i) {
            auto [l, r] = ps[i];
            auto it = ss.lower_bound(l);

            if (it == ss.begin()) {
                qs.push_back(ps[i]);
            } else {
                sum += r;
                ss.erase(--it);
            }
        }

        if (!ss.empty()) continue;
        reverse(qs.begin(), qs.end());

        bool ok = true;
        for (int i = 0; i < n - s; ++i) {
            auto [l, r] = qs[i];
            auto b = bs[i + s];
            if (b <= r) ok = false;
            sum += b;
        }

        if (ok) score = max(score, sum);
    }

    if (score == -1) {
        cout << "NO\n";
    } else {
        cout << "YES\n";
        cout << (score >= m ? "KADOMATSU!" : "NO") << "\n";
    }
}

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

    solve();

    return 0;
}
0