47652023-03-31 11:28:30Albertstein99Óvodacpp17Wrong answer 38/50105ms51000 KiB
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ///READING IN DATA
    long long N, K;
    cin >> N >> K;
    vector <long long> M(K + 1);
    for(long long i = 1; i <= K; i++)
        cin >> M[i];
    vector <long long> S(N + 1);
    for(long long i = 1; i <= N;i++)
        cin >> S[i];
    vector <long long> T(N + 1);
    for(long long i = 1; i <= N;i++)
        cin >> T[i];
    ///STORING DATA IN NEW VARIABLES
    vvpii R(K + 1);
    for(long long 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 <long long> extras;
    for(long long i = 1; i <= K; i++)
        for(long long j = R[i].size(); j < M[i]; j++)
            extras.push_back(i);
    long long db = 1;
    for(long long i = 1; i < extras.size(); i++){
        if(extras[i] != extras[i - 1]) db++;
    }
    long long x = 0, y = 0;
    vector <long long> Xtra(extras.size());
    Xtra[x++] = extras[0];
    for(long long i = 1; i < extras.size(); i++){
        if(extras[i] != extras[i - 1]) Xtra[x++] = extras[i];
        else Xtra[db + y++] = extras[i];
    }
    vector <long long> P(N + 1);
    long long p = 0;
    for(long long i = 1; i <= K; i++){
        long long num = max((signed long long)(R[i].size() - M[i]), 0ll);
        for(long long j = 0; j < num; j++)
            P[R[i][j].second] = Xtra[p++];
        for(long long 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(long long 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 <long long> needs;
    for(long long i = 1; i <= K; i++)
        if(F[i].empty())
            needs.push_back(i);
    vpii usable;
    for(long long i = 1; i <= K; i++){
        for(long long j = 1; j < F[i].size(); j++)
            usable.push_back(F[i][j]);
    }
    ///REASSIGNING ROLES
    sort(usable.begin(), usable.end());
    for(long long i = 0; i < needs.size(); i++){
        P[usable[i].second] = needs[i];
    }
    ///CALCULATING DISSATISFCATION
    long long cry = 0;
    for(long long i = 1; i <= N; i++){
        if(S[i] != P[i])
            cry += T[i];
    }
    cout << cry << "\n";
    for(long long i = 1; i <= N; i++)
        cout << P[i] << " ";
}
SubtaskSumTestVerdictTimeMemory
base38/50
1Accepted0/03ms1832 KiB
2Wrong answer0/06ms3628 KiB
3Accepted2/23ms2268 KiB
4Wrong answer0/23ms2504 KiB
5Accepted2/23ms2700 KiB
6Runtime error0/23ms3004 KiB
7Accepted2/23ms3132 KiB
8Accepted2/22ms3228 KiB
9Accepted2/23ms3424 KiB
10Accepted2/23ms3636 KiB
11Accepted2/23ms3824 KiB
12Accepted2/23ms3916 KiB
13Wrong answer0/23ms4092 KiB
14Accepted3/33ms4052 KiB
15Wrong answer0/310ms7084 KiB
16Wrong answer0/319ms11544 KiB
17Accepted3/332ms16476 KiB
18Accepted3/354ms29592 KiB
19Accepted3/354ms22836 KiB
20Accepted3/359ms23208 KiB
21Accepted3/371ms26424 KiB
22Accepted4/4105ms51000 KiB