47322023-03-31 10:24:24Albertstein99Óvodacpp17Wrong answer 24/50115ms23584 KiB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

int main(){
    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 x = 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[x++];
        for(int j = num; j < R[i].size(); j++)
            P[R[i][j].second] = 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
base24/50
1Accepted0/03ms1808 KiB
2Wrong answer0/07ms2520 KiB
3Accepted2/23ms2356 KiB
4Partially correct1/23ms2508 KiB
5Partially correct1/23ms2720 KiB
6Accepted2/23ms2852 KiB
7Wrong answer0/23ms3096 KiB
8Accepted2/23ms3344 KiB
9Accepted2/22ms3420 KiB
10Accepted2/22ms3420 KiB
11Accepted2/23ms3620 KiB
12Partially correct1/22ms3700 KiB
13Wrong answer0/23ms3756 KiB
14Partially correct1/33ms3896 KiB
15Wrong answer0/314ms4964 KiB
16Wrong answer0/328ms7224 KiB
17Accepted3/337ms7316 KiB
18Wrong answer0/364ms14088 KiB
19Accepted3/365ms9228 KiB
20Partially correct1/371ms9428 KiB
21Partially correct1/385ms10564 KiB
22Wrong answer0/4115ms23584 KiB