47592023-03-31 11:14:28gortomiÓvodacpp17Wrong answer 28/5067ms18940 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> maxi(k + 1), w(n + 1), cry(n + 1), used(k + 1);
    for(int i = 1; i <= k; i++)
    {
        cin >> maxi[i];
    }
    vector<vector<pair<int, int> > > r(k + 1);
    for(int i = 1; i <= n; i++) cin >> w[i];
    for(int i = 1; i <= n; i++) cin >> cry[i];
    vector<pair<int, int> > all;
    for(int i = 1; i <= n; i++)
    {
        r[w[i]].push_back({cry[i], i});
    }
    vector<int> ans(n + 1);
    int sum = 0;
    for(int i = 1; i <= k; i++)
    {
        int a = r[i].size();
        used[i] = min(maxi[i], a);
        sort(r[i].begin(), r[i].end(), greater<pair<int, int> >());
        for(int j = 0; j < min(maxi[i], a); j++)
        {
            all.push_back(r[i][j]);
            ans[r[i][j].second] = i;
        }
        for(int j = maxi[i]; j < r[i].size(); j++)
        {
            all.push_back({0, r[i][j].second});
            sum += r[i][j].first;
        }
    }
    sort(all.begin(), all.end());
    int c = 0;
    int z = 1;
    /*
    while(z <= k)
    {
        while(z <= k && used[z] > 0) z++;
        if(z > k) break;
        while(all[c].first != 0 && used[w[all[c].second]] <= 1)
        {
            c++;
        }
        used[z]++;
        int ind = all[c].second;
        if(all[c].first != 0)
        {
            used[w[ind]]--;
            sum += all[c].first;
        }
        ans[ind] = z;
    }
    */
    int l = 1;
    cout << sum << "\n";
    for(int i = 1; i <= n; i++)
    {
        if(ans[i] == 0)
        {
            while(used[l] == maxi[l])
            {
                l++;
            }
            ans[i] = l;
            used[l]++;
        }
        cout << ans[i] << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
base28/50
1Accepted0/03ms1828 KiB
2Wrong answer0/04ms2732 KiB
3Accepted2/23ms2360 KiB
4Partially correct1/22ms2452 KiB
5Accepted2/23ms2352 KiB
6Accepted2/23ms2576 KiB
7Wrong answer0/22ms2688 KiB
8Partially correct1/23ms3024 KiB
9Accepted2/23ms3156 KiB
10Accepted2/23ms3148 KiB
11Accepted2/23ms3268 KiB
12Partially correct1/23ms3436 KiB
13Wrong answer0/23ms3772 KiB
14Accepted3/33ms3792 KiB
15Wrong answer0/38ms5196 KiB
16Wrong answer0/318ms7716 KiB
17Accepted3/325ms7824 KiB
18Wrong answer0/339ms12076 KiB
19Accepted3/343ms10856 KiB
20Accepted3/350ms11032 KiB
21Partially correct1/356ms12292 KiB
22Wrong answer0/467ms18940 KiB