46612023-03-30 17:23:26ZsofiaKeresztelyÓvodacpp14Runtime error 15/50127ms19580 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--;
        opind++;
    }
    cout << crysum << "\n";
    for (int i=0; i<kids; i++){
        cout << op[i] + 1 << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
base15/50
1Accepted0/03ms1944 KiB
2Accepted0/06ms2684 KiB
3Accepted2/23ms2392 KiB
4Runtime error0/23ms2636 KiB
5Accepted2/22ms2616 KiB
6Runtime error0/23ms2828 KiB
7Wrong answer0/23ms3016 KiB
8Accepted2/23ms3076 KiB
9Accepted2/23ms3204 KiB
10Runtime error0/23ms3540 KiB
11Accepted2/23ms3592 KiB
12Accepted2/22ms3664 KiB
13Wrong answer0/23ms3976 KiB
14Accepted3/33ms4004 KiB
15Wrong answer0/314ms5364 KiB
16Wrong answer0/330ms7552 KiB
17Runtime error0/332ms7232 KiB
18Wrong answer0/371ms12168 KiB
19Runtime error0/357ms10396 KiB
20Runtime error0/361ms10960 KiB
21Runtime error0/374ms11840 KiB
22Wrong answer0/4127ms19580 KiB