結果
問題 |
No.2329 Nafmo、イカサマをする
|
ユーザー |
|
提出日時 | 2023-07-08 10:37:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 1,255 bytes |
コンパイル時間 | 1,038 ms |
コンパイル使用メモリ | 113,380 KB |
最終ジャッジ日時 | 2025-02-15 08:53:45 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include<iostream> #include<set> #include<algorithm> #include<vector> #include<string> #include<set> #include<map> #include<numeric> #include<queue> #include<cmath> #include <unordered_set> using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair<ll,int> P; typedef pair<int,P> PP; const ll MOD=1e9+7; int main(){ int N,M,K; cin>>N>>M>>K; vector<ll> A(N); for(int i=0;i<N;i++)cin>>A[i]; auto dfs=[&](auto f,int idx,int goalidx)->vector<ll>{ if(idx==goalidx){ vector<ll>res={0}; return res; } auto tmpres=f(f,idx+1,goalidx); vector<ll> res=tmpres; for(ll v:tmpres){ for(int i=0;i<N;i++){ if(v+A[i]<=M){ res.push_back(v+A[i]); } } } return res; }; int halfK=K/2; auto res1=dfs(dfs,0,halfK); auto res2=dfs(dfs,halfK,K); sort(res1.begin(),res1.end()); sort(res2.begin(),res2.end()); ll ans=0; for(ll v:res1){ auto it=upper_bound(res2.begin(),res2.end(), M-v); if(it!=res2.begin()){ it--; ll val=(*it + v); ans=max(ans,val); } } cout<<ans<<endl; }