結果

問題 No.2329 Nafmo、イカサマをする
ユーザー FplusFplusF
提出日時 2023-05-28 15:43:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 279 ms / 2,000 ms
コード長 1,441 bytes
コンパイル時間 2,217 ms
コンパイル使用メモリ 200,348 KB
最終ジャッジ日時 2025-02-13 13:50:40
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,m,x;
    cin >> n >> m >> x;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans=0;
    vector<ll> v,vv;
    rep(i,n){
        if(1<=x&&a[i]<=m) chmax(ans,a[i]);
        rep(j,n){
            if(2<=x&&a[i]+a[j]<=m) chmax(ans,a[i]+a[j]);
            vv.push_back(a[i]+a[j]);
            rep(k,n){
                if(3<=x&&a[i]+a[j]+a[k]<=m) chmax(ans,a[i]+a[j]+a[k]);
                v.push_back(a[i]+a[j]+a[k]);
                rep(l,n){
                    if(4<=x&&a[i]+a[j]+a[k]+a[l]<=m) chmax(ans,a[i]+a[j]+a[k]+a[l]);
                }
            }
        }
    }
    sort(all(vv));
    sort(all(v));
    for(auto &i:v){
        if(m<i) continue;
        auto itr=upper_bound(all(vv),m-i);
        if(itr!=vv.begin()) itr--;
        if(5<=x&&i+(*itr)<=m) chmax(ans,i+(*itr));
    }
    for(auto &i:v){
        if(m<i) continue;
        auto itr=upper_bound(all(v),m-i);
        if(itr!=v.begin()) itr--;
        if(6<=x&&i+(*itr)<=m) chmax(ans,i+(*itr));
    }
    cout << ans << '\n';
}
0