13362022-05-14 18:23:08nkdorka1212Óvodacpp11Wrong answer 30/5075ms28576 KiB
#include <bits/stdc++.h>

using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    vector<int>szerep(k+1);
    vector<int>marad(k+1);
    vector<int>v1(n+1);
    vector<int>v2(n+1);
    vector<vector<pair<int,int>>>g(n+1);
    vector<int>veg;
    vector<int>mo(n+1);
    for(int i=1;i<=k;i++)
    {
        cin>>szerep[i];
    }
    marad=szerep;
    for(int i=1;i<=n;i++)
    {
        cin>>v1[i];
        if(marad[v1[i]]>0)
        {
            marad[v1[i]]--;
        }
    }
    for(int i=1;i<=n;i++)
    {
        cin>>v2[i];
    }
    for(int i=1;i<=n;i++)
    {
        g[v1[i]].push_back({v2[i],i});
    }
    for(int i=1;i<=k;i++)
    {
        sort(g[i].rbegin(),g[i].rend());
    }
    for(int i=1;i<=k;i++)
    {
        if(g[i].size()==0)
        {
            veg.push_back(i);
            marad[i]--;
        }
    }
    int cnt=0;
    for(int i=1;i<=k;i++)
    {
        while(marad[i]>0)
        {
            marad[i]--;
            veg.push_back(i);
        }
    }
    long long sir=0;
    vector<int>ok(k+1,0);
    for(int i=1;i<=k;i++)
    {
        for(auto x:g[i])
        {
            if(szerep[i]>0)
            {
                szerep[i]--;
                mo[x.second]=i;
                ok[i]=true;
            }else
            {
                mo[x.second]=veg[cnt];
                cnt++;
                sir+=x.first;
                ok[veg[cnt]]=true;
            }
        }
    }
    vector<pair<int,int>>elek(n+1);
    for(int i=1;i<=n;i++)
    {
        elek[i]={v2[i],i};
    }
    sort(elek.begin(),elek.end());
    int h=1;
    for(int i=1;i<=k;i++)
    {
        if(!ok[i])
        {
            mo[elek[h].second]=i;
        }
    }
    cout<<sir<<'\n';
    for(int i=1;i<=n;i++)
    {
        cout<<mo[i]<<" ";
    }

    return 0;
}

/*
for(int i=1;i<=k;i++)
{
    cout<<i<<'\n';
    for(auto x:g[i])
    {
        cout<<x.first<<" "<<x.second<<" "<<'\n';
    }
}
5 2
2 4
1 1 1 1 2
10 8 9 1 6

*/
SubtaskSumTestVerdictTimeMemory
base30/50
1Accepted0/02ms1812 KiB
2Wrong answer0/03ms2692 KiB
3Accepted2/21ms1904 KiB
4Partially correct1/21ms1908 KiB
5Partially correct1/21ms1908 KiB
6Accepted2/21ms1916 KiB
7Wrong answer0/21ms1920 KiB
8Accepted2/21ms1924 KiB
9Accepted2/21ms1924 KiB
10Accepted2/21ms1928 KiB
11Accepted2/21ms1940 KiB
12Partially correct1/21ms1940 KiB
13Wrong answer0/21ms2028 KiB
14Accepted3/32ms2032 KiB
15Wrong answer0/38ms3844 KiB
16Wrong answer0/317ms6384 KiB
17Accepted3/326ms8896 KiB
18Wrong answer0/341ms14996 KiB
19Accepted3/341ms14364 KiB
20Accepted3/350ms16608 KiB
21Accepted3/356ms18632 KiB
22Wrong answer0/475ms28576 KiB