結果
問題 | No.2329 Nafmo、イカサマをする |
ユーザー | pockyny |
提出日時 | 2023-05-28 15:27:06 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 1,084 bytes |
コンパイル時間 | 1,207 ms |
コンパイル使用メモリ | 85,504 KB |
実行使用メモリ | 7,632 KB |
最終ジャッジ日時 | 2024-12-27 06:42:52 |
合計ジャッジ時間 | 2,575 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; const int B = 3; ll a[110]; vector<ll> v[2]; void dfs(int pos,int n,int cnt,int num, int id,ll sum){ if(pos==n){ v[id].push_back(sum); }else{ dfs(pos + 1,n,cnt,num,id,sum); if(cnt + 1<=num) dfs(pos,n,cnt + 1,num,id,sum + a[pos]); } } int main(){ ll i,j,l,n,m,k; cin >> n >> m >> k; for(i=0;i<n;i++) cin >> a[i]; if(k<=B){ dfs(0,n,0,k,0,0); sort(v[0].rbegin(),v[0].rend()); for(i=0;i<v[0].size();i++){ if(v[0][i]<=m){ cout << v[0][i] << endl; return 0; } } }else{ dfs(0,n,0,B,0,0); dfs(0,n,0,k - B,1,0); sort(v[0].begin(),v[0].end()); sort(v[1].begin(),v[1].end()); ll ans = 0; for(ll x:v[0]){ int pos = upper_bound(v[1].begin(),v[1].end(),m - x) - v[1].begin(); pos--; if(pos>=0) ans = max(ans,x + v[1][pos]); } cout << ans << "\n"; } }