結果
問題 |
No.2686 商品券の使い道
|
ユーザー |
|
提出日時 | 2024-08-17 12:35:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,152 bytes |
コンパイル時間 | 1,323 ms |
コンパイル使用メモリ | 117,372 KB |
最終ジャッジ日時 | 2025-02-23 22:59:16 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 28 TLE * 1 -- * 19 |
ソースコード
#include<iostream> #include<string> #include<queue> #include<vector> #include<cassert> #include<random> #include<set> #include<map> #include<cassert> #include<unordered_map> #include<bitset> #include<numeric> #include<algorithm> using namespace std; typedef long long ll; const int inf=1<<30; const ll INF=1LL<<62; typedef pair<int,ll> P; typedef pair<int,P> PP; const ll MOD=998244353; 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<pair<ll,ll>> dp(1<<N,{0,0}); for(int S=0;S<(1<<N);S++){ for(int i=0;i<N;i++){ if((S>>i)&1){ dp[S].first+=A[i]; dp[S].second+=B[i]; } } } ll ans=0; int all=(1<<N)-1; for(int S=0;S<(1<<N);S++){ if(dp[S].first<=M){ int T=all-S; ans=max(ans,dp[S].second);//2日目を何も買わない for(int t=T;t>0;t=(t-1)&T){ if(dp[t].first<=Q){ ans=max(ans,dp[S].second + dp[t].second); } } } } cout<<ans<<endl; }