結果
問題 | No.2686 商品券の使い道 |
ユーザー |
|
提出日時 | 2024-03-20 23:02:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 173 ms / 3,000 ms |
コード長 | 869 bytes |
コンパイル時間 | 2,089 ms |
コンパイル使用メモリ | 196,812 KB |
最終ジャッジ日時 | 2025-02-20 09:59:33 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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'; }