結果
| 問題 |
No.2329 Nafmo、イカサマをする
|
| コンテスト | |
| ユーザー |
pockyny
|
| 提出日時 | 2023-05-28 15:27:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 2,000 ms |
| コード長 | 1,084 bytes |
| コンパイル時間 | 1,033 ms |
| コンパイル使用メモリ | 83,612 KB |
| 最終ジャッジ日時 | 2025-02-13 13:21:01 |
|
ジャッジサーバー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";
}
}
pockyny