#include<bits/stdc++.h>
using namespace std;
long long a[300005],st[300005],ed[300005];
long long n,k;
priority_queue<long long,vector<long long>,greater<long long>>q;
set<long long>s;
bool b[300005];
int main(){
freopen("interview.in","r",stdin);
freopen("interview.out","w",stdout);
scanf("%lld%lld",&n,&k);
for(long long i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
for(long long i=1;i<=k;i++){
ed[i]=a[i];
q.push(ed[i]);
}
for(long long i=k+1;i<=n;i++){
long long x=q.top();q.pop();
st[i]=x;
ed[i]=x+a[i];
q.push(ed[i]);
}
printf("%lld\n",q.top());
s.insert(q.top());
for(long long i=n;i>=1;i--){
if(s.find(ed[i])!=s.end()){
s.insert(st[i]);
if(i<=k)b[i]=1;
}
}
for(long long i=1;i<=k;i++)printf("%lld",b[i]);
return 0;
}