46812023-03-31 08:45:54AblablablaÓvodacpp17Wrong answer 28/50228ms18940 KiB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;

struct comp{
    bool operator()(vector<int> a, vector<int> b){
        if(a[0] < b[0]){
            return true;
        } else if(a[0] > b[0]){
            return false;
        } else{
            return a[1] < b[1];
        }
    }
};

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> maxi(k + 1, 0);
    for(int i = 1; i <= k; i++){
        cin >> maxi[i];
    }

    vector<vector<int>> szamok(n + 1, vector<int>(3, -1));      // [0] == szerep, [1] == siros perc, [2] == index
    vector<int> betolt(k + 1, 0);
    vector<int> szamokmas(n + 1, 0);

    for(int i = 1; i <= n; i++){
        cin >> szamok[i][0];
        betolt[szamok[i][0]]++;
        szamokmas[i] = szamok[i][0];
        szamok[i][2] = i;
    }

    for(int i = 1; i <= n; i++){
        cin >> szamok[i][1];
    }

    for(int i = 2; i <= k; i++){
        betolt[i] += betolt[i - 1];
    }

    sort(szamok.begin(), szamok.end(), comp());

    vector<bool> siros(n + 1, false);   // true ha az i edik gyerek nem kapja meg a szerepet
    vector<pii> extra;      // index, hany plusz hely van az adott szerepnel
    int valasz = 0;

    for(int i = 1; i <= k; i++){
        int j = betolt[i - 1];
        while(maxi[i] < betolt[i] - j){
            siros[szamok[j + 1][2]] = true;
            valasz += szamok[j + 1][1];
            j++;
        }

        if(maxi[i] > betolt[i] - j){
            extra.push_back({i, maxi[i] - (betolt[i] - j)});
        }
    }

    int extraInd = 0;

    cout << valasz << "\n";

    for(int i = 1; i <= n; i++){
        if(!siros[i]){
            cout << szamokmas[i] << " ";
        } else{
            cout << extra[extraInd].first << " ";
            extra[extraInd].second--;
            if(extra[extraInd].second == 0){
                extraInd++;
            }
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base28/50
1Accepted0/03ms1680 KiB
2Wrong answer0/010ms2628 KiB
3Accepted2/23ms2144 KiB
4Partially correct1/23ms2452 KiB
5Accepted2/23ms2552 KiB
6Accepted2/23ms2772 KiB
7Wrong answer0/23ms2908 KiB
8Partially correct1/23ms3248 KiB
9Accepted2/23ms3212 KiB
10Accepted2/22ms3216 KiB
11Accepted2/23ms3212 KiB
12Partially correct1/23ms3352 KiB
13Wrong answer0/24ms3416 KiB
14Accepted3/34ms3456 KiB
15Wrong answer0/325ms5088 KiB
16Wrong answer0/354ms6996 KiB
17Accepted3/392ms8852 KiB
18Wrong answer0/3130ms12292 KiB
19Accepted3/3164ms13764 KiB
20Accepted3/3193ms14928 KiB
21Partially correct1/3206ms15824 KiB
22Wrong answer0/4228ms18940 KiB