結果

問題 No.2329 Nafmo、イカサマをする
ユーザー Taiki0715Taiki0715
提出日時 2023-05-28 14:30:12
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 2,340 bytes
コンパイル時間 3,460 ms
コンパイル使用メモリ 130,468 KB
実行使用メモリ 13,124 KB
最終ジャッジ日時 2023-08-27 09:59:31
合計ジャッジ時間 5,367 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,504 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 21 ms
5,332 KB
testcase_20 AC 7 ms
4,380 KB
testcase_21 AC 24 ms
5,236 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 8 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 4 ms
4,380 KB
testcase_36 AC 71 ms
7,720 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 97 ms
11,924 KB
testcase_40 AC 96 ms
13,124 KB
testcase_41 AC 153 ms
12,416 KB
testcase_42 AC 97 ms
11,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <cassert>
#include <bitset>
#include <map>
#include <algorithm>
#include <iterator>
#include <string>
#include <utility>
#include <numeric>
#include <regex>
#include <complex>
#include <random>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
  os<<p.first<<" "<<p.second;
  return os;
}
template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
  is>>p.first>>p.second;
  return is;
}
template<typename T>
istream &operator>>(istream &is,vector<T> &a){
  for(auto &i:a)is>>i;
  return is;
}
#define reps(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) reps(i,0,n)
#define all(x) x.begin(),x.end()
ll myceil(ll a,ll b){return (a+b-1)/b;}
int main(){
  int n,m,K;
  cin>>n>>m>>K;
  vector<ll>a(n);
  cin>>a;
  a.push_back(0);
  n++;
  if(K==1){
    ll ans=0;
    for(auto i:a)if(i<=m)chmax(ans,i);
    cout<<ans<<endl;
  }
  else if(K==2){
    ll ans=0;
    for(auto i:a)for(auto j:a)if(i+j<=m)chmax(ans,i+j);
    cout<<ans<<endl;
  }
  else if(K==3){
    ll ans=0;
    for(auto i:a)for(auto j:a)for(auto k:a)if(i+j+k<=m)chmax(ans,i+j+k);
    cout<<ans<<endl;
  }
  else{
    vector<ll>b;
    for(auto i:a)for(auto j:a)b.push_back(i+j);
    vector<ll>c;
    for(auto i:a)for(auto j:a)for(auto k:a)c.push_back(i+j+k);
    sort(all(b)),sort(all(c));
    ll ans=0;
    if(K==4){
      for(auto i:b){
        int cu=upper_bound(all(b),m-i)-b.begin();
        cu--;
        if(cu<0)continue;
        chmax(ans,i+b[cu]);
      }
    }
    else if(K==5){
      for(auto i:b){
        int cu=upper_bound(all(c),m-i)-c.begin();
        cu--;
        if(cu<0)continue;
        chmax(ans,i+c[cu]);
      }
    }
    else{
      for(auto i:c){
        int cu=upper_bound(all(c),m-i)-c.begin();
        cu--;
        if(cu<0)continue;
        chmax(ans,i+c[cu]);
      }
    }
    cout<<ans<<endl;
  }
}
0