結果

問題 No.974 最後の日までに
ユーザー drken1215drken1215
提出日時 2020-01-19 10:00:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 887 ms / 2,000 ms
コード長 1,613 bytes
コンパイル時間 939 ms
コンパイル使用メモリ 85,996 KB
実行使用メモリ 40,576 KB
最終ジャッジ日時 2024-04-14 21:59:11
合計ジャッジ時間 19,974 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 658 ms
40,448 KB
testcase_01 AC 770 ms
40,576 KB
testcase_02 AC 771 ms
40,320 KB
testcase_03 AC 766 ms
40,448 KB
testcase_04 AC 754 ms
40,576 KB
testcase_05 AC 773 ms
40,448 KB
testcase_06 AC 787 ms
40,448 KB
testcase_07 AC 773 ms
40,320 KB
testcase_08 AC 743 ms
40,448 KB
testcase_09 AC 777 ms
40,576 KB
testcase_10 AC 787 ms
40,576 KB
testcase_11 AC 791 ms
40,448 KB
testcase_12 AC 810 ms
40,320 KB
testcase_13 AC 783 ms
40,448 KB
testcase_14 AC 764 ms
40,448 KB
testcase_15 AC 802 ms
40,448 KB
testcase_16 AC 798 ms
40,320 KB
testcase_17 AC 24 ms
6,940 KB
testcase_18 AC 22 ms
6,944 KB
testcase_19 AC 22 ms
6,940 KB
testcase_20 AC 26 ms
6,940 KB
testcase_21 AC 25 ms
6,940 KB
testcase_22 AC 25 ms
6,944 KB
testcase_23 AC 25 ms
6,944 KB
testcase_24 AC 25 ms
6,948 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 624 ms
35,840 KB
testcase_28 AC 878 ms
40,320 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 50 ms
6,940 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 458 ms
26,368 KB
testcase_34 AC 887 ms
40,448 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 1 ms
6,940 KB
testcase_37 AC 77 ms
6,940 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 19 ms
6,944 KB
testcase_41 AC 23 ms
6,940 KB
testcase_42 AC 91 ms
6,940 KB
testcase_43 AC 91 ms
6,940 KB
testcase_44 AC 67 ms
6,940 KB
testcase_45 AC 57 ms
6,944 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,944 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using pll = pair<long long, long long>;
const long long INF = 1LL<<60;
int N;
vector<long long> a, b, c;

// ma[所持金 down 分] = 好感度 up 分
void rec(int n, int finish, map<long long, long long> &ma, long long syoji = 0, long long love = 0) {
    if (n == finish) {
        chmax(ma[-syoji], love);
        return;
    }

    // アルバイト
    rec(n + 1, finish, ma, syoji + a[n], love);

    // 学校からのデート
    if (n + 2 <= finish) rec(n + 2, finish, ma, syoji - c[n+1], love + b[n+1]);
}

long long solve(int mid) {
    // 前半と後半
    map<long long, long long> former, latter;
    rec(0, mid, former);
    rec(mid, N, latter);

    // 後半の累積 max
    long long cur = -INF;
    map<long long, long long> maxlatter;
    maxlatter[-INF] = -INF;
    for (auto it : latter) {
        maxlatter[it.first] = max(cur, it.second);
        chmax(cur, it.second);
    }

    // まとめ
    long long res = 0;
    for (auto it : former) {
        long long need = -(it.first);
        auto it2 = maxlatter.upper_bound(need);
        --it2;
        chmax(res, it.second + it2->second);
    }
    return res;
}

int main() {
    cin >> N;
    a.resize(N), b.resize(N), c.resize(N);
    for (int i = 0; i < N; ++i) cin >> a[i] >> b[i] >> c[i];
    cout << max(solve(N/2), solve(N/2+1)) << endl;
}
0