#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int N,K,A[30]; void solve() { cin >> N >> K; for(int i = 0;i < N;i++) cin >> A[i]; vector D,U; for(int i = 0;i < 1 << N/2;i++) { long long s = 0; for(int j = 0;j < N/2;j++) if(i >> j & 1) s += A[j]; D.push_back(s); } for(int i = 0;i < 1 << N-N/2;i++) { long long s = 0; for(int j = 0;j < N-N/2;j++) if(i >> j & 1) s += A[j+N/2]; U.push_back(s); } sort(D.begin(),D.end(),greater()); sort(U.begin(),U.end()); long long ok = -2e18,ng = 2e18; while(ng-ok > 1) { long long mid = (ok+ng)/2; long long cnt = 0; int id = 0; for(int i = 0;i < (int)D.size();i++) { while(id < (int)U.size() && D[i]+U[id] < mid) id++; cnt += (int)U.size()-id; } if(cnt >= K) ok = mid; else ng = mid; } cout << ok << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; //cin >> tt; while(tt--) solve(); }