結果

問題 No.2686 商品券の使い道
ユーザー GOTKAKOGOTKAKO
提出日時 2024-03-20 22:36:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 3,000 ms
コード長 915 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 202,548 KB
実行使用メモリ 19,928 KB
最終ジャッジ日時 2024-03-20 22:36:47
合計ジャッジ時間 6,239 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 20 ms
7,520 KB
testcase_03 AC 20 ms
7,520 KB
testcase_04 AC 21 ms
7,520 KB
testcase_05 AC 20 ms
7,520 KB
testcase_06 AC 20 ms
7,520 KB
testcase_07 AC 20 ms
7,520 KB
testcase_08 AC 21 ms
7,520 KB
testcase_09 AC 21 ms
7,520 KB
testcase_10 AC 20 ms
7,520 KB
testcase_11 AC 23 ms
7,520 KB
testcase_12 AC 23 ms
7,520 KB
testcase_13 AC 21 ms
7,520 KB
testcase_14 AC 22 ms
7,520 KB
testcase_15 AC 28 ms
7,520 KB
testcase_16 AC 21 ms
7,520 KB
testcase_17 AC 27 ms
7,520 KB
testcase_18 AC 21 ms
7,520 KB
testcase_19 AC 21 ms
7,520 KB
testcase_20 AC 21 ms
7,520 KB
testcase_21 AC 21 ms
7,520 KB
testcase_22 AC 22 ms
7,520 KB
testcase_23 AC 22 ms
7,520 KB
testcase_24 AC 35 ms
7,520 KB
testcase_25 AC 21 ms
7,520 KB
testcase_26 AC 24 ms
7,520 KB
testcase_27 AC 21 ms
7,520 KB
testcase_28 AC 22 ms
7,520 KB
testcase_29 AC 108 ms
19,928 KB
testcase_30 AC 89 ms
19,928 KB
testcase_31 AC 108 ms
19,928 KB
testcase_32 AC 105 ms
19,928 KB
testcase_33 AC 104 ms
19,928 KB
testcase_34 AC 91 ms
19,928 KB
testcase_35 AC 104 ms
19,928 KB
testcase_36 AC 90 ms
19,928 KB
testcase_37 AC 107 ms
19,928 KB
testcase_38 AC 89 ms
19,928 KB
testcase_39 AC 106 ms
19,928 KB
testcase_40 AC 105 ms
19,928 KB
testcase_41 AC 105 ms
19,928 KB
testcase_42 AC 137 ms
19,928 KB
testcase_43 AC 107 ms
19,928 KB
testcase_44 AC 97 ms
19,928 KB
testcase_45 AC 106 ms
19,928 KB
testcase_46 AC 95 ms
19,928 KB
evil_random20_1.txt AC 103 ms
19,928 KB
evil_random20_2.txt AC 89 ms
19,928 KB
evil_random20_3.txt AC 104 ms
19,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M,Q; cin >> N >> M >> Q;
    int A[N],B[N];
    for(int i=0; i<N; i++) cin >> A[i] >> B[i];

    int n2 = 1<<N;
    long long S[n2],S2[n2];
    for(int i=0; i<n2; i++){
        S[i] = 0; S2[i] = 0;
        for(int k=0; k<N; k++) if((i&(1<<k))){
        	S[i] += A[k];
            S2[i] += B[k];
        }
    }

    long long answer = 0;
    for(int i=0; i<n2; i++){
        if(S[i] <= M || S[i] <= Q){answer = max(answer,S2[i]); continue;}

        if(S[i] > M+Q) continue;
        for(int k=(i-1)&i; k>0; k=(k-1)&i){
            int left = i-k;
            if(left >= k) break;

            if(S[k] <= M) if(S[left] <= Q){answer = max(answer,S2[i]); break;}
            if(S[k] <= Q) if(S[left] <= M){answer = max(answer,S2[i]); break;}
        }
    }
    cout << answer << endl;
}
0