47482023-03-31 10:55:49Albertstein99Óvodacpp17Wrong answer 34/5093ms31144 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);
    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];
    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());
    vector <int> extras;
    for(int i = 1; i <= K; i++)
        for(int j = R[i].size(); j < M[i]; j++)
            extras.push_back(i);
    unique(extras.begin(), extras.end());
    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] = extras[p++];
        for(int j = num; j < R[i].size(); j++)
            P[R[i][j].second] = i;
    }
    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]);
    }
    sort(usable.begin(), usable.end());
    for(int i = 0; i < needs.size(); i++){
        P[usable[i].second] = needs[i];
    }
    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
base34/50
1Accepted0/03ms1828 KiB
2Wrong answer0/04ms2768 KiB
3Accepted2/23ms2232 KiB
4Wrong answer0/23ms2444 KiB
5Partially correct1/23ms2656 KiB
6Accepted2/22ms2740 KiB
7Accepted2/22ms2840 KiB
8Accepted2/23ms3104 KiB
9Accepted2/23ms2968 KiB
10Accepted2/23ms3000 KiB
11Accepted2/23ms3072 KiB
12Partially correct1/23ms3200 KiB
13Wrong answer0/23ms3376 KiB
14Partially correct1/33ms3348 KiB
15Wrong answer0/39ms5484 KiB
16Wrong answer0/320ms9208 KiB
17Accepted3/329ms9432 KiB
18Accepted3/348ms17868 KiB
19Accepted3/352ms13232 KiB
20Partially correct1/359ms13176 KiB
21Accepted3/368ms15812 KiB
22Accepted4/493ms31144 KiB