47602023-03-31 11:21:01Albertstein99Óvodacpp17Wrong answer 38/5093ms35876 KiB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ///READING IN DATA
    int N, K;
    cin >> N >> K;
    vector <int> M(K + 1);
    for(int i = 1; i <= K; i++)
        cin >> M[i];
    vector <int> S(N + 1);
    for(int i = 1; i <= N;i++)
        cin >> S[i];
    vector <int> T(N + 1);
    for(int i = 1; i <= N;i++)
        cin >> T[i];
    ///STORING DATA IN NEW VARIABLES
    vvpii R(K + 1);
    for(int i = 1; i <= N; i++)
        R[S[i]].push_back({T[i], i});
    for(auto &x : R)
        sort(x.begin(), x.end());
    ///ASSIGNING EVERYONE A ROLE
    vector <int> extras;
    for(int i = 1; i <= K; i++)
        for(int j = R[i].size(); j < M[i]; j++)
            extras.push_back(i);
    int db = 1;
    for(int i = 1; i < extras.size(); i++){
        if(extras[i] != extras[i - 1]) db++;
    }
    int x = 0, y = 0;
    vector <int> Xtra(extras.size());
    Xtra[x++] = extras[0];
    for(int i = 1; i < extras.size(); i++){
        if(extras[i] != extras[i - 1]) Xtra[x++] = extras[i];
        else Xtra[db + y++] = extras[i];
    }
    vector <int> P(N + 1);
    int p = 0;
    for(int i = 1; i <= K; i++){
        int num = max((signed long long)(R[i].size() - M[i]), 0ll);
        for(int j = 0; j < num; j++)
            P[R[i][j].second] = Xtra[p++];
        for(int j = num; j < R[i].size(); j++)
            P[R[i][j].second] = i;
    }
    ///MAKING SURE EVERY ROLE HAS A PERSON ASSIGNED
    vvpii F(K + 1);
    for(int i = 1; i <= N; i++){
        F[P[i]].push_back({T[i], i});
    }
    for(auto &x : F){
        sort(x.begin(), x.end(), greater<pii>());
    }
    vector <int> needs;
    for(int i = 1; i <= K; i++)
        if(F[i].empty())
            needs.push_back(i);
    vpii usable;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j < F[i].size(); j++)
            usable.push_back(F[i][j]);
    }
    ///REASSIGNING ROLES
    sort(usable.begin(), usable.end());
    for(int i = 0; i < needs.size(); i++){
        P[usable[i].second] = needs[i];
    }
    ///CALCULATING DISSATISFCATION
    int cry = 0;
    for(int i = 1; i <= N; i++){
        if(S[i] != P[i])
            cry += T[i];
    }
    cout << cry << "\n";
    for(int i = 1; i <= N; i++)
        cout << P[i] << " ";
}
SubtaskSumTestVerdictTimeMemory
base38/50
1Accepted0/03ms1828 KiB
2Wrong answer0/04ms2832 KiB
3Accepted2/23ms2228 KiB
4Wrong answer0/23ms2700 KiB
5Accepted2/23ms2840 KiB
6Runtime error0/23ms3148 KiB
7Accepted2/23ms3016 KiB
8Accepted2/23ms3256 KiB
9Accepted2/23ms3448 KiB
10Accepted2/23ms3516 KiB
11Accepted2/23ms3560 KiB
12Accepted2/23ms3680 KiB
13Wrong answer0/23ms4112 KiB
14Accepted3/33ms4040 KiB
15Wrong answer0/39ms6220 KiB
16Wrong answer0/319ms9996 KiB
17Accepted3/328ms10520 KiB
18Accepted3/350ms20760 KiB
19Accepted3/350ms14480 KiB
20Accepted3/357ms14260 KiB
21Accepted3/365ms17112 KiB
22Accepted4/493ms35876 KiB