結果

問題 No.2329 Nafmo、イカサマをする
ユーザー FplusFplusFFplusFplusF
提出日時 2023-05-28 15:43:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 1,441 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 205,632 KB
実行使用メモリ 12,108 KB
最終ジャッジ日時 2023-08-27 12:49:24
合計ジャッジ時間 4,994 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 35 ms
5,080 KB
testcase_20 AC 9 ms
4,376 KB
testcase_21 AC 40 ms
5,196 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 33 ms
5,192 KB
testcase_24 AC 12 ms
4,380 KB
testcase_25 AC 7 ms
4,380 KB
testcase_26 AC 9 ms
4,376 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 4 ms
4,384 KB
testcase_29 AC 8 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 41 ms
7,332 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 10 ms
4,376 KB
testcase_34 AC 12 ms
4,380 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 91 ms
8,808 KB
testcase_37 AC 21 ms
5,200 KB
testcase_38 AC 175 ms
12,108 KB
testcase_39 AC 218 ms
11,632 KB
testcase_40 AC 228 ms
11,408 KB
testcase_41 AC 238 ms
12,048 KB
testcase_42 AC 228 ms
11,460 KB
権限があれば一括ダウンロードができます

ソースコード

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