47392023-03-31 10:31:52gortomiÓvodacpp17Wrong answer 28/5070ms19488 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(used[z] > 0 && z <= k) 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/03ms1956 KiB
2Wrong answer0/04ms2820 KiB
3Accepted2/23ms2268 KiB
4Accepted2/23ms2500 KiB
5Runtime error0/23ms2664 KiB
6Accepted2/23ms2792 KiB
7Wrong answer0/23ms3008 KiB
8Accepted2/23ms3220 KiB
9Accepted2/23ms3420 KiB
10Accepted2/23ms3628 KiB
11Accepted2/23ms3740 KiB
12Partially correct1/23ms4060 KiB
13Wrong answer0/23ms4144 KiB
14Accepted3/33ms4092 KiB
15Wrong answer0/38ms5492 KiB
16Runtime error0/318ms7884 KiB
17Accepted3/325ms7880 KiB
18Wrong answer0/339ms12548 KiB
19Accepted3/343ms11116 KiB
20Accepted3/350ms11544 KiB
21Partially correct1/357ms12792 KiB
22Wrong answer0/470ms19488 KiB