結果

問題 No.2686 商品券の使い道
ユーザー udon1206udon1206
提出日時 2024-03-20 22:49:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 3,000 ms
コード長 1,704 bytes
コンパイル時間 3,236 ms
コンパイル使用メモリ 205,752 KB
実行使用メモリ 19,720 KB
最終ジャッジ日時 2024-03-20 22:49:17
合計ジャッジ時間 7,031 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using ll = long long;
using std::cin;
using std::cout;
using std::endl;

std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

constexpr int inf = (int)1e9 + 7;
constexpr long long INF = 1LL << 60;

void solve()
{
    ll n, M, Q;
    cin >> n >> M >> Q;
    std::vector<ll> w(n), v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> w[i] >> v[i];
    }
    std::vector<ll> dp1(1 << n), dp2(1 << n);
    for (int S = 0; S < (1 << n); S++)
    {
        ll cost = 0;
        ll val = 0;
        for (int i = 0; i < n; i++)
        {
            if (S >> i & 1)
            {
                cost += w[i];
                val += v[i];
            }
        }
        if (cost <= M)
        {
            dp1[S] = val;
        }
        if (cost <= Q)
        {
            dp2[S] = val;
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int S = 0; S < (1 << n); S++)
        {
            if (S >> i & 1)
            {
                continue;
            }
            chmax(dp1[S | 1 << i], dp1[S]);
            chmax(dp2[S | 1 << i], dp2[S]);
        }
    }
    ll res = 0;
    for (int S = 0; S < (1 << n); S++)
    {
        chmax(res, dp1[S] + dp2[((1 << n) - 1) ^ S]);
    }
    cout << res << "\n";
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int kkt = 1;
    // cin >> kkt;
    while (kkt--)
    {
        solve();
    }
}
0