13382022-05-14 19:11:11nkdorka1212Óvodacpp11Wrong answer 27/5079ms28568 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<bool>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;
            sir+=elek[h].first;
        }
    }
    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

6 4
2 1 4 1
2 2 1 3 1 1
4 5 8 9 10 1

*/
SubtaskSumTestVerdictTimeMemory
base27/50
1Accepted0/02ms1840 KiB
2Wrong answer0/06ms2584 KiB
3Accepted2/22ms1900 KiB
4Wrong answer0/21ms1908 KiB
5Wrong answer0/21ms1912 KiB
6Accepted2/21ms1940 KiB
7Wrong answer0/21ms1924 KiB
8Accepted2/21ms1920 KiB
9Accepted2/21ms1932 KiB
10Accepted2/21ms1932 KiB
11Accepted2/21ms1936 KiB
12Wrong answer0/21ms1940 KiB
13Wrong answer0/22ms2028 KiB
14Accepted3/32ms2036 KiB
15Wrong answer0/38ms3844 KiB
16Wrong answer0/318ms6296 KiB
17Accepted3/328ms8896 KiB
18Wrong answer0/345ms15084 KiB
19Accepted3/346ms14368 KiB
20Accepted3/368ms16600 KiB
21Accepted3/359ms18636 KiB
22Wrong answer0/479ms28568 KiB