結果

問題 No.2686 商品券の使い道
ユーザー otoshigootoshigo
提出日時 2024-03-20 23:25:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 3,000 ms
コード長 1,131 bytes
コンパイル時間 1,378 ms
コンパイル使用メモリ 77,840 KB
実行使用メモリ 19,716 KB
最終ジャッジ日時 2024-03-20 23:26:22
合計ジャッジ時間 7,027 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 43 ms
7,424 KB
testcase_04 AC 44 ms
7,424 KB
testcase_05 AC 43 ms
7,424 KB
testcase_06 AC 43 ms
7,424 KB
testcase_07 AC 44 ms
7,424 KB
testcase_08 AC 43 ms
7,424 KB
testcase_09 AC 43 ms
7,424 KB
testcase_10 AC 43 ms
7,424 KB
testcase_11 AC 44 ms
7,424 KB
testcase_12 AC 44 ms
7,424 KB
testcase_13 AC 47 ms
7,424 KB
testcase_14 AC 44 ms
7,424 KB
testcase_15 AC 45 ms
7,424 KB
testcase_16 AC 45 ms
7,424 KB
testcase_17 AC 45 ms
7,424 KB
testcase_18 AC 43 ms
7,424 KB
testcase_19 AC 71 ms
7,424 KB
testcase_20 AC 44 ms
7,424 KB
testcase_21 AC 43 ms
7,424 KB
testcase_22 AC 57 ms
7,424 KB
testcase_23 AC 43 ms
7,424 KB
testcase_24 AC 43 ms
7,424 KB
testcase_25 AC 45 ms
7,424 KB
testcase_26 AC 43 ms
7,424 KB
testcase_27 AC 44 ms
7,424 KB
testcase_28 AC 44 ms
7,424 KB
testcase_29 AC 171 ms
19,716 KB
testcase_30 AC 166 ms
19,716 KB
testcase_31 AC 169 ms
19,716 KB
testcase_32 AC 197 ms
19,716 KB
testcase_33 AC 197 ms
19,716 KB
testcase_34 AC 168 ms
19,716 KB
testcase_35 AC 169 ms
19,716 KB
testcase_36 AC 171 ms
19,716 KB
testcase_37 AC 170 ms
19,716 KB
testcase_38 AC 195 ms
19,716 KB
testcase_39 AC 194 ms
19,716 KB
testcase_40 AC 167 ms
19,716 KB
testcase_41 AC 169 ms
19,716 KB
testcase_42 AC 171 ms
19,716 KB
testcase_43 AC 171 ms
19,716 KB
testcase_44 AC 201 ms
19,716 KB
testcase_45 AC 169 ms
19,716 KB
testcase_46 AC 191 ms
19,716 KB
evil_random20_1.txt AC 166 ms
19,716 KB
evil_random20_2.txt AC 166 ms
19,716 KB
evil_random20_3.txt AC 167 ms
19,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    ll M,Q;
    cin>>N>>M>>Q;
    vector<ll>A(N),B(N);
    for(int i=0;i<N;i++)cin>>A[i]>>B[i];
    vector<ll>V(1<<N),W(1<<N);
    for(int bit=0;bit<1<<N;bit++){
        ll C=0,D=0;
        for(int i=0;i<N;i++){
            if(bit>>i&1){
                C+=A[i];
                D+=B[i];
            }
        }
        if(C<=M)V[bit]=D;
        if(C<=Q)W[bit]=D;
    }
    for(int bit=0;bit<1<<N;bit++){
        for(int i=0;i<N;i++){
            if(bit>>i&1){
                chmax(V[bit],V[bit^(1<<i)]);
                chmax(W[bit],W[bit^(1<<i)]);
            }
        }
    }
    ll ans=0;
    for(int bit=0;bit<1<<N;bit++){
        chmax(ans,V[bit]+W[((1<<N)-1)^bit]);
    }
    cout<<ans<<"\n";
}
0