結果
| 問題 | No.2686 商品券の使い道 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-20 23:02:36 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 133 ms / 3,000 ms |
| コード長 | 869 bytes |
| 記録 | |
| コンパイル時間 | 1,277 ms |
| コンパイル使用メモリ | 214,800 KB |
| 実行使用メモリ | 28,032 KB |
| 最終ジャッジ日時 | 2026-07-04 04:30:06 |
| 合計ジャッジ時間 | 6,327 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 48 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll n, m, q;
cin >> n >> m >> q;
vector<pair<ll,ll>> a(n), b(1 << n);
vector<ll> dp(1 << n);
int U = (1 << n) - 1;
for(auto &&[x, y] : a) cin >> x >> y;
for(int S = 0; S < (1 << n); S++){
for(int i = 0; i < n; i++){
if(S >> i & 1){
b[S].first += a[i].first;
b[S].second += a[i].second;
}
}
if(b[S].first <= m) dp[S ^ U] = b[S].second;
}
ll ans = 0;
for(int S = U; S >= 0; S--){
if(b[S].first <= q){
ans = max(ans, b[S].second + dp[S]);
}
for(int i = 0; i < n; i++){
if(S >> i & 1) dp[S ^ (1 << i)] = max(dp[S ^ (1 << i)], dp[S]);
}
}
cout << ans << '\n';
}