#include using namespace std; #define rep(i, x, limit) for (long long i = (long long)x; i < (long long)limit; i++) #define all(x) x.begin(), x.end() #define el '\n' #define inp(x) for(auto &i:x)cin>>i using ll = long long; using vl = vector; const int MAXS = 1 << 18; // 262144 > 200000 template int solve_bitset(int S, const vector& A){ // Sに必要な最小の2冪サイズまでbitsetを大きくする if constexpr(SZ < MAXS){ if(S >= SZ){ return solve_bitset(S,A); } } bitset dp; dp[0]=1; int n=A.size(); int i=0; // A[i] <= S/2 の要素をDP while(i0;k*=2){ int take=min(k,cnt); ll shift=1LL*A[i]*take; if(shift<=S){ dp|=dp< S/2 は最大1個しか使えない while(i>T; while(T--){ int N,S; cin>>N>>S; vector A(N); inp(A); // Sより大きい要素は絶対使わない vector B; for(auto a:A){ if(a<=S){ B.push_back(a); } } sort(all(B)); N=B.size(); ll sum=0; for(auto a:B){ sum+=a; } // 全部入る if(sum<=S){ cout< dp(1<1){ S/=g; for(auto &a:B){ a/=g; } } int ans=solve_bitset<16>(S,B); cout<<1LL*ans*g<