結果

問題 No.2686 商品券の使い道
ユーザー nononnonon
提出日時 2024-03-21 10:31:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 188 ms / 3,000 ms
コード長 790 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 202,028 KB
実行使用メモリ 11,720 KB
最終ジャッジ日時 2024-03-21 10:31:40
合計ジャッジ時間 9,127 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 41 ms
6,676 KB
testcase_03 AC 41 ms
6,676 KB
testcase_04 AC 41 ms
6,676 KB
testcase_05 AC 40 ms
6,676 KB
testcase_06 AC 40 ms
6,676 KB
testcase_07 AC 41 ms
6,676 KB
testcase_08 AC 41 ms
6,676 KB
testcase_09 AC 41 ms
6,676 KB
testcase_10 AC 40 ms
6,676 KB
testcase_11 AC 40 ms
6,676 KB
testcase_12 AC 41 ms
6,676 KB
testcase_13 AC 41 ms
6,676 KB
testcase_14 AC 40 ms
6,676 KB
testcase_15 AC 40 ms
6,676 KB
testcase_16 AC 40 ms
6,676 KB
testcase_17 AC 40 ms
6,676 KB
testcase_18 AC 40 ms
6,676 KB
testcase_19 AC 41 ms
6,676 KB
testcase_20 AC 41 ms
6,676 KB
testcase_21 AC 40 ms
6,676 KB
testcase_22 AC 40 ms
6,676 KB
testcase_23 AC 40 ms
6,676 KB
testcase_24 AC 40 ms
6,676 KB
testcase_25 AC 41 ms
6,676 KB
testcase_26 AC 40 ms
6,676 KB
testcase_27 AC 41 ms
6,676 KB
testcase_28 AC 42 ms
6,676 KB
testcase_29 AC 166 ms
11,720 KB
testcase_30 AC 167 ms
11,644 KB
testcase_31 AC 165 ms
11,644 KB
testcase_32 AC 188 ms
11,644 KB
testcase_33 AC 165 ms
11,644 KB
testcase_34 AC 167 ms
11,644 KB
testcase_35 AC 166 ms
11,644 KB
testcase_36 AC 166 ms
11,636 KB
testcase_37 AC 164 ms
11,644 KB
testcase_38 AC 167 ms
11,644 KB
testcase_39 AC 164 ms
11,644 KB
testcase_40 AC 165 ms
11,644 KB
testcase_41 AC 170 ms
11,644 KB
testcase_42 AC 164 ms
11,644 KB
testcase_43 AC 165 ms
11,644 KB
testcase_44 AC 164 ms
11,644 KB
testcase_45 AC 166 ms
11,644 KB
testcase_46 AC 169 ms
11,644 KB
evil_random20_1.txt AC 168 ms
11,656 KB
evil_random20_2.txt AC 170 ms
11,644 KB
evil_random20_3.txt AC 173 ms
11,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int N,A[20],B[20];
long M,Q,dp[1<<20];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>N>>M>>Q;
    for(int i=0;i<N;i++)cin>>A[i]>>B[i];
    for(int i=0;i<(1<<N);i++)
    {
        long key=0,val=0;
        for(int j=0;j<N;j++)if(i>>j&1)
        {
            key+=A[j];
            val+=B[j];
        }
        if(key<=M)dp[i]=val;
    }
    for(int j=0;j<N;j++)for(int i=0;i<(1<<N);i++)if(i>>j&1)dp[i]=max(dp[i],dp[i^(1<<j)]);
    long ans=0;
    const int mask=(1<<N)-1;
    for(int i=0;i<(1<<N);i++)
    {
        long key=0,val=0;
        for(int j=0;j<N;j++)if(i>>j&1)
        {
            key+=A[j];
            val+=B[j];
        }
        if(key<=Q)ans=max(ans,val+dp[mask^i]);
    }
    cout<<ans<<endl;
}
0