結果

問題 No.974 最後の日までに
ユーザー shibh308shibh308
提出日時 2019-12-09 18:27:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,427 bytes
コンパイル時間 2,437 ms
コンパイル使用メモリ 149,464 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-07 23:20:49
合計ジャッジ時間 5,285 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 187 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 187 ms
4,380 KB
testcase_08 AC 187 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 WA -
testcase_34 AC 37 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 WA -
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 7 ms
4,380 KB
testcase_45 AC 3 ms
4,376 KB
testcase_46 WA -
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

const i64 MOD = 1000000007;

int n;
vector<i64> a, b, c, r, m;
i64 ans;

i64 greedy(){
    i64 money = 0, ret = 0;
    for(int i = 0; i < n - 1; ++i){
        if(money >= c[i + 1]){
            money -= c[i + 1];
            ret += b[i + 1];
        }
        else{
            money += a[i];
        }
    }
    return ret;
}

// [i, n)
bool cond(int i, i64 money, i64 val){
    if(val + r[i] < ans)
        return false;
    if(money + m[i] < 0)
        return false;
    return true;
}

void search(int i, i64 money, i64 val){
    if(i == n){
        if(money >= 0)
            ans = max(ans, val);
        return;
    }
    if(!cond(i, money, val))
        return;
    if(i != n - 1)
        search(i + 2, money - c[i + 1], val + b[i + 1]);
    search(i + 1, money + a[i], val);
}

signed 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];
    a.emplace_back(0);
    b.emplace_back(0);
    c.emplace_back(0);
    a.emplace_back(0);
    b.emplace_back(0);
    c.emplace_back(0);
    r.resize(n + 1, 0);
    m.resize(n + 1, 0);
    for(int i = n - 2; i >= 0; --i)
        r[i] = max({r[i], r[i + 1], r[i + 2] + b[i + 1]});
    for(int i = n - 1; i >= 0; --i)
        m[i] = m[i + 1] + a[i];

    ans = greedy();

    search(0, 0, 0);

    cout << ans << endl;
}

0