結果

問題 No.2686 商品券の使い道
ユーザー 沙耶花沙耶花
提出日時 2024-03-20 21:56:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 3,000 ms
コード長 1,037 bytes
コンパイル時間 4,363 ms
コンパイル使用メモリ 262,528 KB
実行使用メモリ 11,512 KB
最終ジャッジ日時 2024-03-20 21:56:28
合計ジャッジ時間 9,382 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 4 ms
6,676 KB
testcase_03 AC 4 ms
6,676 KB
testcase_04 AC 4 ms
6,676 KB
testcase_05 AC 4 ms
6,676 KB
testcase_06 AC 4 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 4 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 4 ms
6,676 KB
testcase_11 AC 44 ms
6,676 KB
testcase_12 AC 32 ms
6,676 KB
testcase_13 AC 42 ms
6,676 KB
testcase_14 AC 44 ms
6,676 KB
testcase_15 AC 30 ms
6,676 KB
testcase_16 AC 42 ms
6,676 KB
testcase_17 AC 27 ms
6,676 KB
testcase_18 AC 39 ms
6,676 KB
testcase_19 AC 39 ms
6,676 KB
testcase_20 AC 42 ms
6,676 KB
testcase_21 AC 42 ms
6,676 KB
testcase_22 AC 12 ms
6,676 KB
testcase_23 AC 17 ms
6,676 KB
testcase_24 AC 41 ms
6,676 KB
testcase_25 AC 8 ms
6,676 KB
testcase_26 AC 38 ms
6,676 KB
testcase_27 AC 42 ms
6,676 KB
testcase_28 AC 38 ms
6,676 KB
testcase_29 AC 29 ms
11,512 KB
testcase_30 AC 169 ms
11,512 KB
testcase_31 AC 185 ms
11,512 KB
testcase_32 AC 176 ms
11,512 KB
testcase_33 AC 169 ms
11,512 KB
testcase_34 AC 171 ms
11,512 KB
testcase_35 AC 169 ms
11,512 KB
testcase_36 AC 169 ms
11,512 KB
testcase_37 AC 172 ms
11,512 KB
testcase_38 AC 179 ms
11,512 KB
testcase_39 AC 183 ms
11,512 KB
testcase_40 AC 168 ms
11,512 KB
testcase_41 AC 159 ms
11,512 KB
testcase_42 AC 162 ms
11,512 KB
testcase_43 AC 172 ms
11,512 KB
testcase_44 AC 179 ms
11,512 KB
testcase_45 AC 176 ms
11,512 KB
testcase_46 AC 177 ms
11,512 KB
evil_random20_1.txt AC 8 ms
11,512 KB
evil_random20_2.txt AC 7 ms
11,512 KB
evil_random20_3.txt AC 8 ms
11,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001


int main(){
	
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	int N,M,Q;
	cin>>N>>M>>Q;
	vector<int> a(N),b(N);
	rep(i,N)cin>>a[i]>>b[i];
	vector<pair<int,int>> dp(1<<N,make_pair(3,3));
	dp[0] = make_pair(0,0);
	rep(i,1<<N){
		if(dp[i].first == 3)continue;
		rep(j,N){
			if((i>>j)&1)continue;
			auto c = dp[i];
			if(c.first==0){
				if(c.second + a[j] <= M)c.second += a[j];
				else if(a[j] > Q)continue;
				else {
					c.first = 1;
					c.second = a[j];
				}
			}
			else{
				if(c.second + a[j] > Q)continue;
				c.second += a[j];
			}
			dp[i | (1<<j)] = min(dp[i|(1<<j)],c);
		}
	}
	long long ans = 0;
	rep(i,1<<N){
		if(dp[i].first!=3){
			long long v = 0;
			rep(j,N){
				if((i>>j)&1)v += b[j];
			}
			ans = max(ans,v);
		}
		
	}
	cout<<ans<<endl;
	
	return 0;
}
0