結果

問題 No.2329 Nafmo、イカサマをする
コンテスト
ユーザー momoyuu
提出日時 2023-05-28 14:28:00
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,143 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,693 ms
コンパイル使用メモリ 344,396 KB
実行使用メモリ 13,416 KB
最終ジャッジ日時 2026-11-23 01:03:15
合計ジャッジ時間 4,928 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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;
}
0