結果

問題 No.2686 商品券の使い道
ユーザー aradarad
提出日時 2024-03-01 07:59:42
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 3,000 ms
コード長 1,027 bytes
コンパイル時間 2,887 ms
コンパイル使用メモリ 248,244 KB
実行使用メモリ 27,892 KB
最終ジャッジ日時 2024-03-19 00:37:09
合計ジャッジ時間 7,658 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 35 ms
9,472 KB
testcase_03 AC 35 ms
9,472 KB
testcase_04 AC 36 ms
9,472 KB
testcase_05 AC 34 ms
9,472 KB
testcase_06 AC 35 ms
9,472 KB
testcase_07 AC 35 ms
9,472 KB
testcase_08 AC 35 ms
9,472 KB
testcase_09 AC 35 ms
9,472 KB
testcase_10 AC 35 ms
9,472 KB
testcase_11 AC 35 ms
9,472 KB
testcase_12 AC 35 ms
9,472 KB
testcase_13 AC 36 ms
9,472 KB
testcase_14 AC 35 ms
9,472 KB
testcase_15 AC 34 ms
9,472 KB
testcase_16 AC 34 ms
9,472 KB
testcase_17 AC 34 ms
9,472 KB
testcase_18 AC 34 ms
9,472 KB
testcase_19 AC 35 ms
9,472 KB
testcase_20 AC 35 ms
9,472 KB
testcase_21 AC 34 ms
9,472 KB
testcase_22 AC 34 ms
9,472 KB
testcase_23 AC 34 ms
9,472 KB
testcase_24 AC 35 ms
9,472 KB
testcase_25 AC 34 ms
9,472 KB
testcase_26 AC 35 ms
9,472 KB
testcase_27 AC 34 ms
9,472 KB
testcase_28 AC 35 ms
9,472 KB
testcase_29 AC 138 ms
27,892 KB
testcase_30 AC 138 ms
27,892 KB
testcase_31 AC 138 ms
27,892 KB
testcase_32 AC 137 ms
27,892 KB
testcase_33 AC 137 ms
27,892 KB
testcase_34 AC 137 ms
27,892 KB
testcase_35 AC 138 ms
27,892 KB
testcase_36 AC 138 ms
27,892 KB
testcase_37 AC 137 ms
27,892 KB
testcase_38 AC 137 ms
27,892 KB
testcase_39 AC 137 ms
27,892 KB
testcase_40 AC 138 ms
27,892 KB
testcase_41 AC 138 ms
27,892 KB
testcase_42 AC 139 ms
27,892 KB
testcase_43 AC 139 ms
27,892 KB
testcase_44 AC 138 ms
27,892 KB
testcase_45 AC 138 ms
27,892 KB
testcase_46 AC 139 ms
27,892 KB
evil_random20_1.txt AC 138 ms
27,892 KB
evil_random20_2.txt AC 139 ms
27,892 KB
evil_random20_3.txt AC 138 ms
27,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;

int main(){
    ll n,m,q;
    cin >> n >> m >> q;
    vector<ll> a(n),b(n);
    ll n2 = 1<<n;
    vector<ll> w(n2);
    for(ll i = 0;i < n;i++){
        cin >> a[i] >> b[i];
        for(ll j = 0;j < n2;j++){
            if(j>>i&1) w[i] += a[i];
        }
    }
    vector<ll> dpm(n2),dpq(n2);
    for(ll i = 0;i < n2;i++){
        ll suma = 0,sumb = 0;
         for(ll j = 0;j < n;j++){
            if(i>>j&1){
                suma += a[j];
                sumb += b[j];
            }
        }
        if(suma <= m) dpm[i] = sumb;
        if(suma <= q) dpq[i] = sumb;
    }
    for(ll i = 0;i < n;i++){
        for(ll j = 0;j < n2;j++){
            if(j>>i&1){
                dpm[j] = max(dpm[j],dpm[j-(1<<i)]);
                dpq[j] = max(dpq[j],dpq[j-(1<<i)]);
            }
        }
    }
    ll ans = 0;
    for(ll i = 0;i < n2;i++){
        ll j = (n2-1)^i;
        ans = max(ans,dpm[i]+dpq[j]);
    }
    cout << ans << endl;
}
0