結果

問題 No.974 最後の日までに
ユーザー kimiyukikimiyuki
提出日時 2020-01-18 07:14:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 2,057 bytes
コンパイル時間 2,315 ms
コンパイル使用メモリ 207,124 KB
実行使用メモリ 23,592 KB
最終ジャッジ日時 2024-04-14 21:53:05
合計ジャッジ時間 7,438 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
22,736 KB
testcase_01 AC 94 ms
22,076 KB
testcase_02 AC 93 ms
21,996 KB
testcase_03 AC 93 ms
22,572 KB
testcase_04 AC 92 ms
23,124 KB
testcase_05 AC 95 ms
21,936 KB
testcase_06 AC 93 ms
23,592 KB
testcase_07 AC 92 ms
22,700 KB
testcase_08 AC 93 ms
23,036 KB
testcase_09 AC 92 ms
23,256 KB
testcase_10 AC 94 ms
23,372 KB
testcase_11 AC 89 ms
22,488 KB
testcase_12 AC 90 ms
22,072 KB
testcase_13 AC 93 ms
22,300 KB
testcase_14 AC 93 ms
22,296 KB
testcase_15 AC 90 ms
23,488 KB
testcase_16 AC 90 ms
22,600 KB
testcase_17 AC 101 ms
23,340 KB
testcase_18 AC 103 ms
22,136 KB
testcase_19 AC 103 ms
21,908 KB
testcase_20 AC 101 ms
22,016 KB
testcase_21 AC 104 ms
22,360 KB
testcase_22 AC 105 ms
22,660 KB
testcase_23 AC 107 ms
22,988 KB
testcase_24 AC 104 ms
22,136 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 72 ms
16,300 KB
testcase_28 AC 93 ms
22,452 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 105 ms
22,028 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 63 ms
15,788 KB
testcase_34 AC 98 ms
22,904 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 108 ms
22,344 KB
testcase_38 AC 1 ms
6,940 KB
testcase_39 AC 1 ms
6,940 KB
testcase_40 AC 66 ms
16,040 KB
testcase_41 AC 83 ms
22,296 KB
testcase_42 AC 106 ms
21,976 KB
testcase_43 AC 110 ms
22,828 KB
testcase_44 AC 83 ms
16,040 KB
testcase_45 AC 71 ms
15,144 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 AC 1 ms
6,944 KB
testcase_51 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }

int64_t solve(int w, const vector<int64_t> & a, const vector<int64_t> & b, const vector<int64_t> & c) {
    auto func = [&](int l, int r) {
        vector<pair<int64_t, int64_t> > nxt, cur, prv;
        cur.emplace_back(0, 0);
        REP3 (i, l, r) {
            prv.swap(cur);
            cur.swap(nxt);
            nxt.clear();
            for (auto it : prv) {
                cur.emplace_back(it.first + a[i], it.second);
                if (i + 1 < r) {
                    nxt.emplace_back(it.first - c[i + 1], it.second + b[i + 1]);
                }
            }
        }
        sort(ALL(cur));
        nxt.clear();
        for (auto it : cur) {
            while (not nxt.empty() and nxt.back().second <= it.second) {
                nxt.pop_back();
            }
            nxt.push_back(it);
        }
        return nxt;
    };

    auto merge = [&](const vector<pair<int64_t, int64_t> > & dp1, const vector<pair<int64_t, int64_t> > & dp2) {
        int64_t ans = INT64_MIN;
        for (auto it1 : dp1) {
            auto it2 = lower_bound(ALL(dp2), make_pair(- it1.first, INT64_MIN));
            if (it2 != dp2.end()) {
                chmax(ans, it1.second + it2->second);
            }
        }
        return ans;
    };

    int hw = w / 2;
    auto l1 = func(0, hw);
    auto r1 = func(hw, w);
    auto l2 = func(0, hw + 1);
    auto r2 = func(hw + 1, w);
    return max(merge(l1, r1), merge(l2, r2));
}

int main() {
    int w; cin >> w;
    vector<int64_t> a(w), b(w), c(w);
    REP (i, w) {
        cin >> a[i] >> b[i] >> c[i];
    }
    cout << solve(w, a, b, c) << endl;
    return 0;
}
0