結果

問題 No.2686 商品券の使い道
ユーザー new_textfilenew_textfile
提出日時 2024-03-20 23:12:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 3,000 ms
コード長 2,810 bytes
コンパイル時間 4,786 ms
コンパイル使用メモリ 262,976 KB
実行使用メモリ 19,692 KB
最終ジャッジ日時 2024-03-20 23:13:03
合計ジャッジ時間 9,644 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
// #include <atcoder/modint>
// #include <atcoder/math>
// #include <atcoder/segtree>
// #include <atcoder/lazysegtree>
// #include <atcoder/dsu>
// #include <atcoder/scc>
using namespace atcoder;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef priority_queue<pll, vpll, function<bool(pll,pll)> > pqpll; 
typedef priority_queue<ll, vll, function<bool(pll,pll)> > pqll;
 
struct edge{ ll to, cost; edge(ll e_to,ll e_cost): to(e_to), cost(e_cost){} };
typedef vector<vector<edge>> Graph;
 
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (1LL << 60)
#define INF (1 << 30)
#define fs first
#define sc second
#define EPS (ld)1e-10
#define ALL(a) a.begin(), a.end()
#define tcheck(a) if((clock() - start)/(ld)CLOCKS_PER_SEC >= a) break
#define debug(s) cout << #s << endl
#define debugval(x) cout << #x" = " << x << endl
 
template<typename T> ll sz(vector<T> &pos){ return (ll)pos.size(); }
template<typename T> ll sz(priority_queue<T, vector<T> > &que) {return (ll)que.size(); }
template<typename T> ll sz(priority_queue<T, vector<T>, greater<T> > &que) {return (ll)que.size(); }
ll sz(string &s) {return (ll)s.size(); } 
 
template<typename T> void chmin(T &a, T b) { if(a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if(a < b) a = b; }

// __int128_t gcd(__int128_t a, __int128_t b){ return ((!b) ? a : gcd(b,a%b)); } 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
ll dx[4] = {0,-1,0,1},dy[4] = {-1,0,1,0};
// ll dx[8] = {0,-1,-1,-1,0,1,1,1},dy[8] = {-1,-1,0,1,1,1,0,-1};
inline bool isinside(ll i,ll n){ return (i < n && i >= 0); }

int main(){
    ll n,m,q;
    cin >> n >> m >> q;

    vll a(n),b(n);
    rep(i,0,n) cin >> a[i] >> b[i];

    vll memo1(1ll << n), memo2(1ll << n);
    rep(bit,0,1ll << n){
        ll vsum = 0, wsum = 0;
        rep(i,0,n){
            if((bit >> i) & 1){
                vsum += b[i];
                wsum += a[i];  

                chmax(memo1[bit], memo1[bit ^ (1ll << i)]);
                chmax(memo2[bit], memo2[bit ^ (1ll << i)]);
            }
        }
        if(wsum <= m) chmax(memo1[bit], vsum);
        if(wsum <= q) chmax(memo2[bit], vsum);
    }

    ll ans = 0;
    rep(bit,0,1ll << n) chmax(ans, memo1[bit] + memo2[((1ll << n)-1) ^ bit]);
    cout << ans << endl;
}
0