148752025-02-05 18:29:25antiÓvodacpp17Wrong answer 17/50500ms4148 KiB
#include <iostream>
#include <algorithm>

using namespace std;

struct gyerek{
    int szerep, siras, sorsz;
};

bool comp1(gyerek a, gyerek b){
    if(a.szerep != b.szerep){
        return a.szerep < b.szerep;
    }else if(a.siras != b.siras){
        return a.siras > b.siras;
    }else{
        return a.sorsz < b.sorsz;
    }
}

bool comp2(gyerek a, gyerek b){
    if(a.siras != b.siras){
        return a.siras < b.siras;
    }else if(a.sorsz != b.sorsz){
        return a.sorsz > b.sorsz;
    }else{
        return a.szerep < b.szerep;
    }
}

int main()
{
    int n, k;
    cin >> n >> k;
    gyerek gy[n];
    int m[k], meg[n], M[k], Min=0;
    bool v[n] = {0}, e[k] = {0};
    for(int i=0; i<k; i++){
        cin >> m[i];
        M[i] = m[i];
    }
    for(int i=0; i<n; i++){
        cin >> gy[i].szerep;
        gy[i].szerep--;
        gy[i].sorsz = i;
    }
    for(int i=0; i<n; i++){
        cin >> gy[i].siras;
    }
    sort(gy, gy+n, comp1);


    for(int i=0; i<n; i++){
        if(m[gy[i].szerep] > 0){
            meg[gy[i].sorsz] = gy[i].szerep + 1;
            m[gy[i].szerep]--;
            v[gy[i].sorsz] = 1;
            e[gy[i].szerep] = 1;
        }
    }
    sort(gy, gy+n, comp2);
    for(int i=0; i<k; i++){
        if(e[i] == 0){
            for(int j=0; j<n; j++){
                if(v[gy[j].sorsz] == 0){
                    meg[gy[j].sorsz] = i+1;
                    m[i]--;
                    v[gy[j].sorsz] = 1;
                    e[i] = 1;
                }
            }
        }
    }
    bool kesz;
    int h;
    for(int i=0; i<k; i++){
        if(e[i] == 0){
            kesz = false;
            h=0;
            while(kesz == false){
                if(M[meg[gy[h].sorsz]] > 1){
                    meg[gy[h].sorsz] = i;
                    kesz = true;
                }else
                    h++;
            }
        }
    }
    for(int i=0; i<n; i++){
        if(gy[i].szerep + 1 != meg[gy[i].sorsz]){
            Min += gy[i].siras;
        }
    }
    cout << Min << endl;
    for(int i=0; i<n; i++){
        cout << meg[i] << " ";
    }

}
SubtaskSumTestVerdictTimeMemory
base17/50
1Accepted0/01ms496 KiB
2Wrong answer0/06ms316 KiB
3Partially correct1/21ms316 KiB
4Accepted2/21ms508 KiB
5Partially correct1/21ms1012 KiB
6Accepted2/21ms564 KiB
7Wrong answer0/21ms512 KiB
8Partially correct1/21ms500 KiB
9Accepted2/21ms316 KiB
10Accepted2/21ms316 KiB
11Partially correct1/21ms316 KiB
12Partially correct1/21ms316 KiB
13Wrong answer0/22ms316 KiB
14Partially correct1/32ms508 KiB
15Wrong answer0/328ms820 KiB
16Runtime error0/3337ms1324 KiB
17Partially correct1/350ms1588 KiB
18Time limit exceeded0/3500ms2316 KiB
19Partially correct1/389ms2868 KiB
20Partially correct1/398ms2964 KiB
21Wrong answer0/3115ms3636 KiB
22Time limit exceeded0/4485ms4148 KiB