結果

問題 No.1341 真ん中を入れ替えて門松列
ユーザー MisterMister
提出日時 2021-01-15 22:42:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,572 bytes
コンパイル時間 1,117 ms
コンパイル使用メモリ 94,616 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-17 18:00:56
合計ジャッジ時間 5,900 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 320 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 117 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 712 ms
4,376 KB
testcase_15 AC 634 ms
4,380 KB
testcase_16 AC 629 ms
4,376 KB
testcase_17 AC 639 ms
4,380 KB
testcase_18 AC 83 ms
4,376 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;
        bool ok = true;

        set<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()) {
                sum += r;
                ss.erase(--it);
            } else {
                qs.push_back(ps[i]);
            }
        }

        if (!ss.empty()) continue;

        reverse(qs.begin(), qs.end());
        for (int i = 0; i < n - s; ++i) {
            auto [l, r] = qs[i];
            auto b = bs[i + s];
            if (r >= b) 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