%%%http://blog.csdn.net/lych_cys/article/details/51033694
1 #include<bits/stdc++.h> 2 #define INF 0x7fffffff 3 #define LL long long 4 #define N 1000005 5 using namespace std; 6 inline int ra() 7 { 8 int x=0,f=1; char ch=getchar(); 9 while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();} 10 while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();} 11 return x*f; 12 } 13 int n,m,cnt,tp,a[N],num[N],val[N<<2],sk[N]; 14 LL ans[N]; 15 struct node{ 16 LL x; int y; 17 }; 18 priority_queue<node> q; 19 bool operator <(node a, node b) 20 { 21 return a.x>b.x; 22 } 23 void build(int k, int l, int r) 24 { 25 if (l==r) 26 { 27 val[k]=a[l]; return; 28 } 29 int mid=l+r>>1; 30 build(k<<1,l,mid); build(k<<1|1,mid+1,r); 31 val[k]=min(val[k<<1],val[k<<1|1]); 32 } 33 int query(int k, int l, int r, int x, LL y) 34 { 35 if (x<=l) 36 { 37 if (val[k]>y) return 0; 38 if (l==r) return l; 39 } 40 int mid=l+r>>1; 41 if (x<=mid) 42 { 43 int t=query(k<<1,l,mid,x,y); 44 if (t) return t; 45 } 46 return query(k<<1|1,mid+1,r,x,y); 47 } 48 void dfs(int k, LL rst) 49 { 50 if (!cnt) return ; int i; 51 if (!rst) 52 { 53 cnt--; 54 if (!cnt) for (i=1; i<=tp; i++) printf("%d ",sk[i]); 55 return; 56 } 57 for (i=k+1; i<=n; i++) 58 { 59 i=query(1,1,n,i,rst); 60 if (i) 61 { 62 sk[++tp]=i; 63 dfs(i,rst-a[i]); 64 tp--; 65 } 66 else break; 67 } 68 } 69 int main() 70 { 71 n=ra(); m=ra()-1; 72 if (!m) 73 { 74 cout<<"0"; 75 return 0; 76 } 77 for (int i=1; i<=n; i++) a[i]=num[i]=ra(); 78 sort(num+1,num+n+1); 79 node u; u.x=num[1]; u.y=1; q.push(u); 80 for (int i=1; i<=m; i++) 81 { 82 u=q.top(); q.pop(); ans[i]=u.x; 83 if (i<m && u.y<n) 84 { 85 u.y++; u.x+=num[u.y]; q.push(u); 86 u.x-=num[u.y-1]; q.push(u); 87 } 88 } 89 for (int i=m; i && ans[i]==ans[m]; i--) cnt++; 90 printf("%lld ",ans[m]); 91 build(1,1,n); 92 dfs(0,ans[m]); 93 return 0; 94 }