这题感觉和图上k短路很类似,,用优先队列一直弹弹弹直到弹满k个就好了
/*%%%%%%%%%%%%%lcy%%%%%%%%%%%%%%%%%%%%*/
#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<queue>
#include<string.h>
#include<string>
#include<cstring>
#include<vector>
#include<time.h>
#include<stdlib.h>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define FIN freopen("input.txt","r",stdin);
#define mem(x,y) memset(x,y,sizeof(x));
typedef unsigned long long ULL;
typedef long long LL;
#define fuck(x) cout<<x<<endl;
const int MX=2e5+5;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<pair<int,int>,int> PIII;
typedef pair<LL,int> PII;
const double eps=1e-9;
int w[MX],n,k;
int main()
{
FIN;
while(cin>>n>>k)
{
for(int i=0; i<n; i++)scanf("%d",&w[i]);
sort(w,w+n);
priority_queue<PII,vector<PII>,greater<PII> >Q;
LL ans;
int cnt=0;
Q.push(PII(w[0],0));
while(!Q.empty())
{
PII u=Q.top();
Q.pop();
//cout<<u.first<<endl;
cnt++;
if(cnt==k)
{
ans=u.first;
break;
}
if(u.second+1<n)
{
Q.push(PII(u.first+w[u.second+1],u.second+1));
Q.push(PII(u.first+w[u.second+1]-w[u.second],u.second+1));
}
}
cout<<ans<<endl;
}
return 0;
}