48352023-03-31 13:31:30ZsofiaKeresztelyÓvodacpp14Elfogadva 50/50116ms18740 KiB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second

/*
10 1
10
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
*/

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++){
        if (!cry[i].size()){
            wasnt.push_back(left.size());
            left.push_back({places[i], i});
            continue;
        }
        sort(cry[i].rbegin(), cry[i].rend());
        op[cry[i][0].se] = i;
        for (int j=1; 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()){
            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 (lind < left.size() && !left[lind].fi) lind++;
        if (lind == left.size()) break;
        while (opind < kids && op[opind] >= 0) opind++;
        if (opind == kids) break;
        op[opind] = left[lind].se;
        left[lind].fi--;
        opind++;
    }
    cout << crysum << "\n";
    for (int i=0; i<kids; i++){
        cout << op[i] + 1 << " ";
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms1808 KiB
2Elfogadva0/07ms2652 KiB
3Elfogadva2/23ms2388 KiB
4Elfogadva2/23ms2644 KiB
5Elfogadva2/23ms2768 KiB
6Elfogadva2/23ms2776 KiB
7Elfogadva2/23ms2988 KiB
8Elfogadva2/23ms3200 KiB
9Elfogadva2/22ms3284 KiB
10Elfogadva2/23ms3472 KiB
11Elfogadva2/23ms3832 KiB
12Elfogadva2/23ms3864 KiB
13Elfogadva2/23ms4056 KiB
14Elfogadva3/33ms3896 KiB
15Elfogadva3/314ms5132 KiB
16Elfogadva3/328ms7068 KiB
17Elfogadva3/337ms7084 KiB
18Elfogadva3/368ms11692 KiB
19Elfogadva3/365ms10236 KiB
20Elfogadva3/371ms10400 KiB
21Elfogadva3/389ms11828 KiB
22Elfogadva4/4116ms18740 KiB