結果

問題 No.2686 商品券の使い道
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-04-05 00:44:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 684 ms / 3,000 ms
コード長 875 bytes
コンパイル時間 2,453 ms
コンパイル使用メモリ 207,404 KB
実行使用メモリ 208,176 KB
最終ジャッジ日時 2024-04-05 00:44:36
合計ジャッジ時間 21,632 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 133 ms
50,460 KB
testcase_03 AC 133 ms
50,460 KB
testcase_04 AC 132 ms
50,460 KB
testcase_05 AC 133 ms
50,460 KB
testcase_06 AC 132 ms
50,460 KB
testcase_07 AC 136 ms
50,460 KB
testcase_08 AC 163 ms
50,460 KB
testcase_09 AC 135 ms
50,460 KB
testcase_10 AC 136 ms
50,460 KB
testcase_11 AC 136 ms
50,460 KB
testcase_12 AC 135 ms
50,460 KB
testcase_13 AC 135 ms
50,460 KB
testcase_14 AC 133 ms
50,460 KB
testcase_15 AC 133 ms
50,460 KB
testcase_16 AC 132 ms
50,460 KB
testcase_17 AC 135 ms
50,460 KB
testcase_18 AC 145 ms
50,460 KB
testcase_19 AC 135 ms
50,460 KB
testcase_20 AC 136 ms
50,460 KB
testcase_21 AC 135 ms
50,460 KB
testcase_22 AC 137 ms
50,460 KB
testcase_23 AC 139 ms
50,460 KB
testcase_24 AC 138 ms
50,460 KB
testcase_25 AC 138 ms
50,460 KB
testcase_26 AC 136 ms
50,460 KB
testcase_27 AC 161 ms
50,460 KB
testcase_28 AC 133 ms
50,460 KB
testcase_29 AC 654 ms
208,176 KB
testcase_30 AC 683 ms
208,176 KB
testcase_31 AC 657 ms
208,176 KB
testcase_32 AC 678 ms
208,176 KB
testcase_33 AC 658 ms
208,176 KB
testcase_34 AC 684 ms
208,176 KB
testcase_35 AC 657 ms
208,176 KB
testcase_36 AC 681 ms
208,176 KB
testcase_37 AC 648 ms
208,176 KB
testcase_38 AC 675 ms
208,176 KB
testcase_39 AC 644 ms
208,176 KB
testcase_40 AC 680 ms
208,176 KB
testcase_41 AC 653 ms
208,176 KB
testcase_42 AC 659 ms
208,176 KB
testcase_43 AC 663 ms
208,176 KB
testcase_44 AC 650 ms
208,176 KB
testcase_45 AC 678 ms
208,176 KB
testcase_46 AC 656 ms
208,176 KB
evil_random20_1.txt AC 678 ms
208,176 KB
evil_random20_2.txt AC 654 ms
208,176 KB
evil_random20_3.txt AC 674 ms
208,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	int N;ll 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<vector<ll>> dp(1 << N, vector<ll>(N + 1, 0));
	for (int bit = 0;bit < (1 << N);bit++) {
		ll m = 0;ll v = 0;
		for (int i = 0;i < N;i++) if (bit & (1 << i)) m += A[i],v += B[i];
		if (m <= Q) dp[bit][0] = v;
	}
	for (int i = 0;i < N;i++) for (int bit = 0;bit < (1 << N);bit++) {
		if (bit & (1 << i)) {
			dp[bit][i + 1] = max(dp[bit][i], dp[bit & ~(1 << i)][i]);
		} else {
			dp[bit][i + 1] = dp[bit][i];
		}
	}
	ll ans = 0;
	for (int bit = 0;bit < (1 << N);bit++) {
		ll m = 0;ll v = 0;
		for (int i = 0;i < N;i++) if (bit & (1 << i)) m += A[i],v += B[i];
		if (m > M) continue;
		int tbit = ((1 << N) - 1) ^ bit;
		ans = max(ans, dp[tbit][N] + v);
	}
	cout << ans << endl;
}
0