結果

問題 No.2329 Nafmo、イカサマをする
ユーザー umezoumezo
提出日時 2023-05-28 15:49:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,327 bytes
コンパイル時間 2,429 ms
コンパイル使用メモリ 207,156 KB
実行使用メモリ 12,836 KB
最終ジャッジ日時 2023-08-27 13:04:47
合計ジャッジ時間 4,815 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 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 1 ms
4,384 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 20 ms
5,188 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 23 ms
5,272 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 26 ms
5,152 KB
testcase_24 AC 10 ms
4,380 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 8 ms
4,376 KB
testcase_27 AC 7 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 31 ms
8,240 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 6 ms
4,380 KB
testcase_34 AC 10 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 59 ms
7,844 KB
testcase_37 AC 17 ms
5,272 KB
testcase_38 AC 96 ms
12,372 KB
testcase_39 AC 110 ms
12,248 KB
testcase_40 AC 98 ms
11,744 KB
testcase_41 AC 129 ms
12,108 KB
testcase_42 AC 98 ms
12,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll n,m,k;
  cin>>n>>m>>k;
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  
  vector<ll> A2;
  rep(i,n) rep(j,n) A2.push_back(A[i]+A[j]);
  
  vector<ll> A3;
  rep(i,n) rep(j,n*n) A3.push_back(A[i]+A2[j]);
  
  sort(ALL(A)),sort(ALL(A2)),sort(ALL(A3));
  ll ans=0;
  auto a=upper_bound(ALL(A),m)-A.begin();
  if(a){
    a--;
    ans=A[a];
  }
  if(k>1){
    auto a2=upper_bound(ALL(A2),m)-A2.begin();
    if(a2){
      a2--;
      ans=max(ans,A2[a2]);
    }
  }
  if(k>2){
    auto a3=upper_bound(ALL(A3),m)-A3.begin();
    if(a3){
      a3--;
      ans=max(ans,A3[a3]);
    }
  }
  if(k>3){
    rep(i,n*n){
      auto a4=upper_bound(ALL(A2),m-A2[i])-A2.begin();
      if(a4){
        a4--;
        ans=max(ans,A2[i]+A2[a4]);
      }
    }
  }
  if(k>4){
    rep(i,n*n*n){
      auto a5=upper_bound(ALL(A2),m-A3[i])-A2.begin();
      if(a5){
        a5--;
        ans=max(ans,A3[i]+A2[a5]);
      }
    }
  }
  if(k>5){
    rep(i,n*n*n){
      auto a6=upper_bound(ALL(A3),m-A3[i])-A3.begin();
      if(a6){
        a6--;
        ans=max(ans,A3[i]+A3[a6]);
      }
    }
  }
  cout<<ans<<endl;
    
  return 0;
}
0