結果

問題 No.974 最後の日までに
ユーザー drken1215drken1215
提出日時 2020-01-19 09:52:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,514 bytes
コンパイル時間 946 ms
コンパイル使用メモリ 86,280 KB
実行使用メモリ 50,988 KB
最終ジャッジ日時 2023-09-15 19:53:30
合計ジャッジ時間 29,289 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1,143 ms
50,668 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1,149 ms
50,708 KB
testcase_06 AC 1,104 ms
50,928 KB
testcase_07 AC 1,164 ms
50,676 KB
testcase_08 AC 1,083 ms
50,672 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1,187 ms
50,712 KB
testcase_14 AC 1,108 ms
50,688 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 31 ms
4,380 KB
testcase_18 AC 29 ms
4,384 KB
testcase_19 AC 29 ms
4,380 KB
testcase_20 AC 33 ms
4,380 KB
testcase_21 AC 33 ms
4,380 KB
testcase_22 AC 32 ms
4,376 KB
testcase_23 AC 32 ms
4,376 KB
testcase_24 AC 32 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 70 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 WA -
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,388 KB
testcase_40 AC 25 ms
4,376 KB
testcase_41 AC 30 ms
4,384 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 1 ms
4,380 KB
testcase_47 WA -
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,380 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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




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

// 後半の各所持金差額に対する獲得好感度の差分ん最大値を求める
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);
    long long cur = -INF;
    map<long long, long long> maxlatter;
    maxlatter[-INF] = -INF;
    for (auto it : latter) maxlatter[it.first] = max(cur, it.second);

    //COUT(former); COUT(latter); COUT(maxlatter);

    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);

        //cout << pll(it.first, it.second) << ": " << pll(it2->first, it2->second) << endl;
    }
    return res;
}

int main() {
    while (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(max(0, N/2-1)), max(solve(N/2), solve(N/2+1))) << endl;
    }
}
0