47652023-03-31 11:28:30Albertstein99Óvodacpp17Hibás válasz 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] << " ";
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base38/50
1Elfogadva0/03ms1832 KiB
2Hibás válasz0/06ms3628 KiB
3Elfogadva2/23ms2268 KiB
4Hibás válasz0/23ms2504 KiB
5Elfogadva2/23ms2700 KiB
6Futási hiba0/23ms3004 KiB
7Elfogadva2/23ms3132 KiB
8Elfogadva2/22ms3228 KiB
9Elfogadva2/23ms3424 KiB
10Elfogadva2/23ms3636 KiB
11Elfogadva2/23ms3824 KiB
12Elfogadva2/23ms3916 KiB
13Hibás válasz0/23ms4092 KiB
14Elfogadva3/33ms4052 KiB
15Hibás válasz0/310ms7084 KiB
16Hibás válasz0/319ms11544 KiB
17Elfogadva3/332ms16476 KiB
18Elfogadva3/354ms29592 KiB
19Elfogadva3/354ms22836 KiB
20Elfogadva3/359ms23208 KiB
21Elfogadva3/371ms26424 KiB
22Elfogadva4/4105ms51000 KiB