#include using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); ll N, K; cin >> N >> K; vector A(N); ll max = 0; for(ll& a : A) { cin >> a; if(a >= 0) max += a; else a = -a; } static bitset<1 << 30> used; priority_queue q(greater<>{}, vector>{}); auto push = [&](int bit, ll cost) { if(used[bit]) return; used[bit] = 1; q.emplace(cost, bit); }; push(0, 0); while(1) { auto [c, bit] = q.top(); q.pop(); if(--K == 0) { cout << max - c << endl; return 0; } for(int i = 0; i < N; i++) if(~bit & 1 << i) push(bit | 1 << i, c + A[i]); } }