結果
問題 | No.2329 Nafmo、イカサマをする |
ユーザー |
![]() |
提出日時 | 2023-05-28 15:49:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 125 ms / 2,000 ms |
コード長 | 1,327 bytes |
コンパイル時間 | 2,020 ms |
コンパイル使用メモリ | 201,156 KB |
最終ジャッジ日時 | 2025-02-13 14:06:54 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#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; }