結果

問題 No.974 最後の日までに
ユーザー parukiparuki
提出日時 2020-01-26 10:35:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 2,657 bytes
コンパイル時間 2,047 ms
コンパイル使用メモリ 179,956 KB
実行使用メモリ 13,524 KB
最終ジャッジ日時 2024-04-14 22:01:45
合計ジャッジ時間 9,128 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
13,524 KB
testcase_01 AC 151 ms
13,396 KB
testcase_02 AC 153 ms
13,324 KB
testcase_03 AC 149 ms
13,352 KB
testcase_04 AC 149 ms
13,292 KB
testcase_05 AC 151 ms
13,256 KB
testcase_06 AC 152 ms
13,320 KB
testcase_07 AC 152 ms
13,404 KB
testcase_08 AC 151 ms
13,356 KB
testcase_09 AC 150 ms
13,236 KB
testcase_10 AC 150 ms
13,240 KB
testcase_11 AC 149 ms
13,256 KB
testcase_12 AC 145 ms
13,308 KB
testcase_13 AC 152 ms
13,356 KB
testcase_14 AC 148 ms
13,248 KB
testcase_15 AC 146 ms
13,252 KB
testcase_16 AC 148 ms
13,380 KB
testcase_17 AC 165 ms
13,236 KB
testcase_18 AC 164 ms
13,360 KB
testcase_19 AC 163 ms
13,240 KB
testcase_20 AC 164 ms
13,172 KB
testcase_21 AC 165 ms
13,220 KB
testcase_22 AC 163 ms
13,172 KB
testcase_23 AC 164 ms
13,172 KB
testcase_24 AC 162 ms
13,172 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 117 ms
8,548 KB
testcase_28 AC 154 ms
13,256 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 164 ms
13,276 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 95 ms
9,060 KB
testcase_34 AC 154 ms
13,232 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 166 ms
13,296 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 105 ms
8,552 KB
testcase_41 AC 137 ms
13,352 KB
testcase_42 AC 164 ms
13,248 KB
testcase_43 AC 165 ms
13,320 KB
testcase_44 AC 124 ms
8,548 KB
testcase_45 AC 100 ms
9,372 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 2 ms
6,944 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

struct P{ ll a,b,c; };

void solve() {
    int W;
    cin >> W;

    vll A(W), B(W), C(W);
    rep(i, W) {
        cin >> A[i] >> B[i] >> C[i];
    }

    auto g = [&](vector<P> p) {
        vi S{ 0 };
        for (int i = 1; i < sz(p); ++i) {
            int n = sz(S);
            rep(j, n) {
                int U = S[j];
                if (!(U >> (i - 1) & 1)) {
                    S.push_back(U | 1 << i);
                }
            }
        }

        int n = sz(S);
        // (money, likes)
        vector<pair<ll, ll> > res(n);
        rep(i, n) {
            int U = S[i];
            if (sz(p) > 0) {
                res[i].first += p[0].a;
            }
            for (int j = 1; j < sz(p); ++j) {
                if (U >> j & 1) {
                    // 前回はアルバイトができなかった
                    res[i].first -= p[j - 1].a + p[j].c;
                    res[i].second += p[j].b;
                } else {
                    res[i].first += p[j].a;
                }
            }
        }

        sort(all(res));
        // (money, likes)
        vector<pair<ll, ll> > so;
        each(r, res) {
            while (sz(so) && so.back().second <= r.second) {
                so.pop_back();
            }
            so.push_back(r);
        }
        return so;
    };

    ll ans = 0;

    auto f = [&](int n) {
        // [0, n), [n, W)
        vector<P> pre, pos;
        rep(i, n) {
            pre.push_back(P{ A[i],B[i],C[i] });
        }
        FOR(i, n, W) {
            pos.push_back(P{ A[i],B[i],C[i] });
        }

        auto L = g(pre);
        auto R = g(pos);
        each(le, L) {
            auto itri = lower_bound(all(R), pair<ll, ll>(-le.first, 0));
            if (itri == R.end()) {
                continue;
            }
            assert(le.first + itri->first >= 0);
            smax(ans, le.second + itri->second);
        }
    };

    f(W / 2);
    f(W / 2 + 1);
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0