結果
| 問題 |
No.2329 Nafmo、イカサマをする
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2023-05-28 14:28:00 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 176 ms / 2,000 ms |
| コード長 | 1,143 bytes |
| コンパイル時間 | 6,455 ms |
| コンパイル使用メモリ | 252,824 KB |
| 実行使用メモリ | 11,604 KB |
| 最終ジャッジ日時 | 2024-12-27 01:25:23 |
| 合計ジャッジ時間 | 7,094 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
int n,m,k;
cin>>n>>m>>k;
vector<ll> a(n);
for(int i = 0;i<n;i++){
cin>>a[i];
}
a.push_back(0);
n++;
vector<ll> use;
if(k<=3){
ll ans = 0;
for(int i = 0;i<n;i++) for(int j = 0;j<n;j++) for(int l = 0;l<n;l++){
ll now = a[i];
if(k>=2) now += a[j];
if(k==3) now += a[l];
if(now<=m) ans = max(now,ans);
}
cout<<ans<<endl;
return 0;
}
for(int i = 0;i<n;i++) for(int j = 0;j<n;j++) for(int l = 0;l<n;l++){
use.push_back(a[i]+a[j]+a[l]);
}
sort(use.begin(),use.end());
ll ans = 0;
for(int i = 0;i<n;i++) for(int j = 0;j<n;j++) for(int l = 0;l<n;l++){
ll now = a[i];
if(k>=5) now += a[j];
if(k==6) now += a[l];
ll want = m - now;
if(want<0) continue;
int ni = upper_bound(use.begin(),use.end(),want) - use.begin();
ni--;
assert(ni<use.size());
ll can = now + use[ni];
if(can<=m) ans = max(ans,can);
}
cout<<ans<<endl;
}
momoyuu