結果

問題 No.2686 商品券の使い道
ユーザー SnowBeenDidingSnowBeenDiding
提出日時 2024-03-20 23:43:03
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 206 ms / 3,000 ms
コード長 1,070 bytes
コンパイル時間 3,291 ms
コンパイル使用メモリ 250,140 KB
実行使用メモリ 19,688 KB
最終ジャッジ日時 2024-03-20 23:43:13
合計ジャッジ時間 10,048 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 43 ms
7,424 KB
testcase_03 AC 44 ms
7,424 KB
testcase_04 AC 44 ms
7,424 KB
testcase_05 AC 45 ms
7,424 KB
testcase_06 AC 44 ms
7,424 KB
testcase_07 AC 45 ms
7,424 KB
testcase_08 AC 44 ms
7,424 KB
testcase_09 AC 44 ms
7,424 KB
testcase_10 AC 44 ms
7,424 KB
testcase_11 AC 46 ms
7,424 KB
testcase_12 AC 44 ms
7,424 KB
testcase_13 AC 44 ms
7,424 KB
testcase_14 AC 45 ms
7,424 KB
testcase_15 AC 44 ms
7,424 KB
testcase_16 AC 44 ms
7,424 KB
testcase_17 AC 45 ms
7,424 KB
testcase_18 AC 44 ms
7,424 KB
testcase_19 AC 44 ms
7,424 KB
testcase_20 AC 45 ms
7,424 KB
testcase_21 AC 45 ms
7,424 KB
testcase_22 AC 44 ms
7,424 KB
testcase_23 AC 45 ms
7,424 KB
testcase_24 AC 47 ms
7,424 KB
testcase_25 AC 44 ms
7,424 KB
testcase_26 AC 45 ms
7,424 KB
testcase_27 AC 44 ms
7,424 KB
testcase_28 AC 44 ms
7,424 KB
testcase_29 AC 178 ms
19,688 KB
testcase_30 AC 172 ms
19,688 KB
testcase_31 AC 172 ms
19,688 KB
testcase_32 AC 173 ms
19,688 KB
testcase_33 AC 177 ms
19,688 KB
testcase_34 AC 174 ms
19,688 KB
testcase_35 AC 174 ms
19,688 KB
testcase_36 AC 173 ms
19,688 KB
testcase_37 AC 170 ms
19,688 KB
testcase_38 AC 171 ms
19,688 KB
testcase_39 AC 182 ms
19,688 KB
testcase_40 AC 206 ms
19,688 KB
testcase_41 AC 176 ms
19,688 KB
testcase_42 AC 178 ms
19,688 KB
testcase_43 AC 179 ms
19,688 KB
testcase_44 AC 182 ms
19,688 KB
testcase_45 AC 177 ms
19,688 KB
testcase_46 AC 190 ms
19,688 KB
evil_random20_1.txt AC 174 ms
19,688 KB
evil_random20_2.txt AC 174 ms
19,688 KB
evil_random20_3.txt AC 173 ms
19,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace std;

typedef long long ll;

int n, m, q;
vector<int> p, v;

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

int main() {
    cin >> n >> m >> q;
    p.resize(n);
    v.resize(n);
    rep(i, 0, n) cin >> p[i] >> v[i];
    vector<ll> x(1 << n), y(1 << n);
    rep(i, 0, 1 << n) {
        ll sump = 0, sumv = 0;
        rep(j, 0, n) {
            if (i >> j & 1) {
                sump += p[j];
                sumv += v[j];
            }
        }
        if (sump <= m) x[i] = sumv;
        if (sump <= q) y[i] = sumv;
    }
    for (int bit = 0; bit < (1 << n); ++bit) {
        for (int i = 0; i < n; ++i) {
            if ((1 << i) & bit) continue;
            chmax(x[(1 << i) | bit], x[bit]);
            chmax(y[(1 << i) | bit], y[bit]);
        }
    }
    ll ans = 0;
    int mask = (1 << n) - 1;
    rep(i, 0, 1 << n) chmax(ans, x[i] + y[mask ^ i]);
    cout << ans << endl;
}
0