46512023-03-30 14:24:30ZsofiaKeresztelyÓvodacpp14Runtime error 15/50127ms18820 KiB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second

int main()
{
    int kids, roles;
    cin >> kids >> roles;
    vector<int> places(roles), pref(kids), op(kids, -1), wasnt;
    vector<vector<pii> > cry(roles);
    vector<pii> left, fix;
    for (int i=0; i<roles; i++){
        cin >> places[i];
    }
    for (int i=0; i<kids; i++){
        cin >> pref[i];
    }
    for (int i=0; i<kids; i++){
        int a;
        cin >> a;
        cry[pref[i]-1].push_back({a, i});
    }
    long long crysum = 0;
    for (int i=0; i<roles; i++){
        sort(cry[i].rbegin(), cry[i].rend());
        for (int j=0; j<min((int)cry[i].size(), places[i]); j++){
            op[cry[i][j].se] = i;
            fix.push_back(cry[i][j]);
        }
        for (int j=min((int)cry[i].size(), places[i]); j<cry[i].size(); j++){
            crysum += cry[i][j].fi;
        }
        if (places[i] > cry[i].size()){
            if (!cry[i].size()) wasnt.push_back(left.size());
            left.push_back({places[i] - cry[i].size(), i});
        }
    }
    int lind = 0, opind = 0;
    while (lind < wasnt.size()){
        while (opind < kids && op[opind] >= 0){
            opind++;
        }
        if (opind == kids) break;
        op[opind] = left[wasnt[lind]].se;
        left[wasnt[lind]].fi--;
        lind++;
    }
    if (lind < wasnt.size()){
        sort(fix.begin(), fix.end());
        for (int i=lind; i<wasnt.size(); i++){
            crysum += fix[i-lind].fi;
            op[fix[i-lind].se] = left[wasnt[i]].se;
            left[wasnt[i]].fi--;
        }
    }
    lind = 0;
    while (opind < kids){
        while (!left[lind].fi) lind++;
        while (op[opind] > 0) opind++;
        op[opind] = left[lind].se;
        left[lind].fi--;
    }
    cout << crysum << "\n";
    for (int i=0; i<kids; i++){
        cout << op[i] + 1 << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
base15/50
1Runtime error0/03ms1912 KiB
2Wrong answer0/07ms2516 KiB
3Partially correct1/23ms2216 KiB
4Partially correct1/23ms2300 KiB
5Partially correct1/23ms2560 KiB
6Runtime error0/23ms2612 KiB
7Wrong answer0/23ms2660 KiB
8Accepted2/23ms2660 KiB
9Partially correct1/23ms2852 KiB
10Accepted2/22ms2932 KiB
11Runtime error0/23ms3036 KiB
12Accepted2/23ms3064 KiB
13Wrong answer0/23ms3208 KiB
14Partially correct1/33ms3184 KiB
15Wrong answer0/314ms4392 KiB
16Wrong answer0/332ms6728 KiB
17Partially correct1/337ms6620 KiB
18Wrong answer0/371ms11156 KiB
19Partially correct1/367ms9596 KiB
20Partially correct1/371ms10012 KiB
21Partially correct1/386ms11336 KiB
22Wrong answer0/4127ms18820 KiB