結果

問題 No.2686 商品券の使い道
ユーザー てんぷらてんぷら
提出日時 2024-03-21 01:50:14
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 161 ms / 3,000 ms
コード長 1,262 bytes
コンパイル時間 9,710 ms
コンパイル使用メモリ 307,076 KB
実行使用メモリ 11,516 KB
最終ジャッジ日時 2024-03-21 01:50:37
合計ジャッジ時間 11,487 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 39 ms
6,548 KB
testcase_03 AC 39 ms
6,548 KB
testcase_04 AC 39 ms
6,548 KB
testcase_05 AC 39 ms
6,548 KB
testcase_06 AC 39 ms
6,548 KB
testcase_07 AC 45 ms
6,548 KB
testcase_08 AC 39 ms
6,548 KB
testcase_09 AC 39 ms
6,548 KB
testcase_10 AC 40 ms
6,548 KB
testcase_11 AC 39 ms
6,548 KB
testcase_12 AC 39 ms
6,548 KB
testcase_13 AC 39 ms
6,548 KB
testcase_14 AC 39 ms
6,548 KB
testcase_15 AC 39 ms
6,548 KB
testcase_16 AC 39 ms
6,548 KB
testcase_17 AC 39 ms
6,548 KB
testcase_18 AC 39 ms
6,548 KB
testcase_19 AC 39 ms
6,548 KB
testcase_20 AC 38 ms
6,548 KB
testcase_21 AC 39 ms
6,548 KB
testcase_22 AC 39 ms
6,548 KB
testcase_23 AC 39 ms
6,548 KB
testcase_24 AC 39 ms
6,548 KB
testcase_25 AC 39 ms
6,548 KB
testcase_26 AC 39 ms
6,548 KB
testcase_27 AC 39 ms
6,548 KB
testcase_28 AC 39 ms
6,548 KB
testcase_29 AC 158 ms
11,516 KB
testcase_30 AC 158 ms
11,516 KB
testcase_31 AC 158 ms
11,516 KB
testcase_32 AC 157 ms
11,516 KB
testcase_33 AC 161 ms
11,516 KB
testcase_34 AC 158 ms
11,516 KB
testcase_35 AC 158 ms
11,516 KB
testcase_36 AC 157 ms
11,516 KB
testcase_37 AC 160 ms
11,516 KB
testcase_38 AC 157 ms
11,516 KB
testcase_39 AC 158 ms
11,516 KB
testcase_40 AC 158 ms
11,516 KB
testcase_41 AC 157 ms
11,516 KB
testcase_42 AC 158 ms
11,516 KB
testcase_43 AC 159 ms
11,516 KB
testcase_44 AC 160 ms
11,516 KB
testcase_45 AC 158 ms
11,516 KB
testcase_46 AC 158 ms
11,516 KB
evil_random20_1.txt AC 159 ms
11,516 KB
evil_random20_2.txt AC 158 ms
11,516 KB
evil_random20_3.txt AC 159 ms
11,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
using namespace std;
using namespace atcoder;
using mint = modint998244353;
const int inf = 1000000007;
const ll longinf = 1ll << 60;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q1, q2;
    cin >> n >> q1 >> q2;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    int all = 1 << n;
    vector<ll> dp(all);
    rep(i, all) {
        ll v = 0, p = 0;
        rep(j, n) {
            if(i >> j & 1) {
                p += a[j];
                v += b[j];
            }
        }
        if(p <= q1) {
            dp[i] = v;
        }
    }
    rep(j, n) rep(i, all) {
        if(!(i >> j & 1)) {
            dp[i | (1 << j)] = max(dp[i | (1 << j)], dp[i]);
        }
    }
    ll ans = 0;
    rep(i, all) {
        ll v = 0, p = 0;
        rep(j, n) {
            if(i >> j & 1) {
                p += a[j];
                v += b[j];
            }
        }
        if(p <= q2) {
            ans = max(ans, v + dp[(all - 1) ^ i]);
        }
    }
    cout << ans << endl;
    return 0;
}
0