結果

問題 No.2686 商品券の使い道
ユーザー shinchanshinchan
提出日時 2024-03-21 00:42:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 298 ms / 3,000 ms
コード長 1,192 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 204,852 KB
実行使用メモリ 19,716 KB
最終ジャッジ日時 2024-03-21 00:42:40
合計ジャッジ時間 11,378 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 69 ms
7,424 KB
testcase_03 AC 69 ms
7,424 KB
testcase_04 AC 69 ms
7,424 KB
testcase_05 AC 69 ms
7,424 KB
testcase_06 AC 70 ms
7,424 KB
testcase_07 AC 69 ms
7,424 KB
testcase_08 AC 69 ms
7,424 KB
testcase_09 AC 68 ms
7,424 KB
testcase_10 AC 68 ms
7,424 KB
testcase_11 AC 68 ms
7,424 KB
testcase_12 AC 69 ms
7,424 KB
testcase_13 AC 68 ms
7,424 KB
testcase_14 AC 69 ms
7,424 KB
testcase_15 AC 69 ms
7,424 KB
testcase_16 AC 69 ms
7,424 KB
testcase_17 AC 69 ms
7,424 KB
testcase_18 AC 69 ms
7,424 KB
testcase_19 AC 68 ms
7,424 KB
testcase_20 AC 70 ms
7,424 KB
testcase_21 AC 69 ms
7,424 KB
testcase_22 AC 69 ms
7,424 KB
testcase_23 AC 68 ms
7,424 KB
testcase_24 AC 68 ms
7,424 KB
testcase_25 AC 69 ms
7,424 KB
testcase_26 AC 68 ms
7,424 KB
testcase_27 AC 69 ms
7,424 KB
testcase_28 AC 69 ms
7,424 KB
testcase_29 AC 280 ms
19,716 KB
testcase_30 AC 281 ms
19,716 KB
testcase_31 AC 278 ms
19,716 KB
testcase_32 AC 280 ms
19,716 KB
testcase_33 AC 280 ms
19,716 KB
testcase_34 AC 281 ms
19,716 KB
testcase_35 AC 280 ms
19,716 KB
testcase_36 AC 279 ms
19,716 KB
testcase_37 AC 298 ms
19,716 KB
testcase_38 AC 284 ms
19,716 KB
testcase_39 AC 279 ms
19,716 KB
testcase_40 AC 281 ms
19,716 KB
testcase_41 AC 280 ms
19,716 KB
testcase_42 AC 279 ms
19,716 KB
testcase_43 AC 280 ms
19,716 KB
testcase_44 AC 277 ms
19,716 KB
testcase_45 AC 280 ms
19,716 KB
testcase_46 AC 281 ms
19,716 KB
evil_random20_1.txt AC 283 ms
19,716 KB
evil_random20_2.txt AC 281 ms
19,716 KB
evil_random20_3.txt AC 281 ms
19,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto&& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

void chmax(ll &a, ll b) { a = max(a, b); }
vector<ll> solve(ll n, ll x, vector<ll> &w, vector<ll> &v) {
    ll mask = 1LL << n;
    vector<ll> dp(mask, 0);
    rep(bit, mask) {
        ll sumx = 0, sum = 0;
        rep(i, n) if(bit >> i & 1) {
            sumx += w[i];
            sum += v[i];
        }
        if(sumx <= x) dp[bit] = sum;
    }
    rep(bit, mask) {
        rep(i, n) if(bit >> i & 1) {
            chmax(dp[bit], dp[bit ^ (1 << i)]);
        }
    }
    return dp;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, q;
    cin >> n >> m >> q;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    auto dp1 = solve(n, m, a, b);
    auto dp2 = solve(n, q, a, b);
    ll ans = 0;
    ll mask = (1LL << n);
    rep(i, mask) chmax(ans, dp1[i] + dp2[(mask - 1) ^ i]);
    cout << ans << endl;
    return 0;
}
0