比赛 |
20241023 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
Bessie’s Interview |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
3.946 s |
代码语言 |
C++ |
内存使用 |
18.77 MiB |
提交时间 |
2024-10-23 10:15:38 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 3e5+10;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n,k;
ll a[N];
bool v[N];
set<pii>s;
struct node{ll l,r,id;};
vector<node>vec[N];
int main(){
freopen("interview.in","r",stdin);
freopen("interview.out","w",stdout);
n = read(),k = read();
for(int i = 1;i <= n;i++)a[i] = read();
for(int i = 1;i <= k;i++)s.insert({a[i],i});
int i = k,cnt = 0;
while(1){
auto w = *s.begin();
++cnt;
while(s.size() && (*s.begin()).fi == w.fi && i <= n){
auto x = (*s.begin());s.erase(x);
s.insert({x.fi + a[++i],x.se});
vec[cnt].pb({x.fi,x.fi + a[i],x.se});
}
if(i == n + 1)break;
}
auto w = *s.begin();
while(s.size() && (*s.begin()).fi == w.fi){
auto x = *(s.begin());s.erase(x);
v[x.se] = 1;
}
for(int i = cnt;i >= 1;i--){
bool f = 0;
for(node it : vec[i]){
f |= v[it.id];
s.erase({it.r,it.id}),s.insert({it.l,it.id});
}
if(!f)continue;
for(node it : vec[i])v[it.id] = i;
}
printf("%lld\n",w.fi);
for(int i = 1;i <= k;i++)printf("%d",v[i]);
printf("\n");
return 0;
}