結果

問題 No.2686 商品券の使い道
ユーザー KKT89
提出日時 2024-03-20 22:37:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 211 ms / 3,000 ms
コード長 1,331 bytes
コンパイル時間 2,567 ms
コンパイル使用メモリ 213,636 KB
最終ジャッジ日時 2025-02-20 09:39:30
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,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> uo(1<<n);
    for (int i = 0; i < (1<<n); ++i) {
        ll sum = 0, val = 0;
        for (int j = 0; j < n; ++j) {
            if ((1<<j)&i) {
                sum += a[j], val += b[j];
            }
        }
        if (sum <= q) uo[i] = val;
        for (int j = 0; j < n; ++j) {
            if ((1<<j)&i) uo[i] = max(uo[i], uo[i-(1<<j)]);
        }
    }
    ll res = 0;
    for (int i = 0; i < (1<<n); ++i) {
        ll sum = 0, val = 0;
        for (int j = 0; j < n; ++j) {
            if ((1<<j)&i) {
                sum += a[j], val += b[j];
            }
        }
        if (sum <= m) {
            res = max(res, val+uo[(1<<n)-1-i]);
        }
    }
    cout << res << endl;
}
0