比赛 20241023 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 Bessie’s Interview 最终得分 100
用户昵称 darkMoon 运行时间 3.344 s
代码语言 C++ 内存使用 11.85 MiB
提交时间 2024-10-23 09:14:26
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
auto IN = freopen("interview.in", "r", stdin);
auto OUT = freopen("interview.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 3e5 + 5;
int n = mread(), m = mread(), a[N], f[N];
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;
vector<vector<pair<int, int> > > v2;
signed main(){
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 1; i <= m; i ++){
        q.push(mp(a[i], i));
    }
    int p = m + 1;
    vector<pair<int, int> > v;
    int ans = 0, res = 0;
    while(q.size() && p >= 0){
        int now = q.top().fi, fi = q.top().se;
        while(q.size() && q.top().fi == now){
            auto tmp = q.top();
            v.push_back(tmp);
            q.pop();
        }
        for(auto tmp : v){
            if(p <= n){
                q.push(mp(tmp.fi + a[p ++], tmp.se));
            }
            else{
                ans = tmp.fi;
                res = tmp.se;
                p = -1;
                break;
            }
        }
        v.clear();
    }
    for(int i = 1; i <= m; i ++){
        q.push(mp(a[i], i));
    }
    p = m + 1;
    while(q.size() && p >= 0){
        int now = q.top().fi, fi = q.top().se;
        while(q.size() && q.top().fi == now){
            auto tmp = q.top();
            v.push_back(tmp);
            q.pop();
        }
        v2.push_back(v);
        for(auto tmp : v){
            if(p <= n){
                q.push(mp(tmp.fi + a[p ++], tmp.se));
            }
            else{
                p = -1;
                break;
            }
        }
        v.clear();
    }
    f[res] = 1;
    for(int i = v2.size() - 1; i >= 0; i --){
        auto tmp = v2[i];
        int ee = 0;
        for(auto t : tmp){
            if(f[t.se]){
                ee = 1;
            }
        }
        if(ee){
            for(auto t : tmp){
                f[t.se] = 1;
            }
        }
    }
    printf("%lld\n", ans);
    for(int i = 1; i <= m; i ++){
        cout << f[i];
    }
    return 0;
}