85252024-01-21 08:38:06MagyarKendeSZLGÓvodacpp17Wrong answer 33/50266ms10820 KiB

#include <bits/stdc++.h>

#pragma region Utility

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define cinv(v) for (auto& e : v) cin >> e;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define size(v) (int)v.size()
#define has(s, e) s.count(e)

#define max_index(v) max_element(all(v)) - v.begin()
#define min_index(v) min_element(all(v)) - v.begin()
#define smax(x, y) x = max(x, y)
#define smin(x, y) x = min(x, y)

#define sum(v) accumulate(all(v), 0)
#define product(v, T) accumulate(all(v), 1, multiplies<T>())

using namespace std;
using ll = long long;
using point = array<int, 2>;

int max(point p) { return max(p[0], p[1]); }
int min(point p) { return min(p[0], p[1]); }

template <typename T>
vector<T> prefix_sum(const vector<T>& v) {
    vector<T> result(size(v));
    partial_sum(all(v), result.begin());
    return result;
}

#pragma endregion

#ifdef NATIVERUN
#define cin fin
#endif

int main() {
    #ifndef NATIVERUN
    speed;
    #else
    ifstream fin("input.txt");
    #endif

    int N, K;
    cin >> N >> K;

    vector<int> roleS(K), wantS(K);
    cinv(roleS);

    vector<int> orig_roleS = roleS;

    priority_queue<array<int, 3>> pq;
    
    vector<point> kidS(N);
    for (point& p : kidS) cin >> p[0];
    for (point& p : kidS) cin >> p[1];

    for (int i = 0; i < N; i++) {
        pq.push({kidS[i][1], kidS[i][0] - 1, i});
        wantS[kidS[i][0] - 1]++;
    }

    int total_cry = 0;
    vector<int> result(N);

    while (!pq.empty()) {
        auto [cry, kid, i] = pq.top(); pq.pop();

        if (cry == 0) {
            bool put = 0;
            for (int j = 0; j < K; j++) {
                if (roleS[j] == orig_roleS[j]) {
                    roleS[j]--;
                    result[i] = j;
                    put = 1;
                    break;
                }
            }
            if (put) continue;
            for (int j = 0; j < K; j++) {
                if (roleS[j] > 0) {
                    roleS[j]--;
                    result[i] = j;
                    break;
                }
            }
        }
        else if (roleS[kid] > 0) {
            roleS[kid]--;
            wantS[kid]--;
            result[i] = kid;
        } 
        else {
            total_cry += cry;
            pq.push({0, -1, i});
        }
    }

    cout << total_cry << '\n';
    for (int x : result) cout << x + 1 << ' ';
}
SubtaskSumTestVerdictTimeMemory
base33/50
1Accepted0/03ms1960 KiB
2Accepted0/04ms2548 KiB
3Accepted2/23ms2356 KiB
4Accepted2/23ms2568 KiB
5Accepted2/23ms2716 KiB
6Accepted2/22ms2708 KiB
7Wrong answer0/22ms2708 KiB
8Accepted2/23ms2936 KiB
9Accepted2/22ms2936 KiB
10Accepted2/23ms3064 KiB
11Accepted2/22ms3092 KiB
12Accepted2/23ms3220 KiB
13Wrong answer0/23ms3344 KiB
14Accepted3/33ms3340 KiB
15Wrong answer0/314ms4352 KiB
16Wrong answer0/3118ms5440 KiB
17Accepted3/327ms5980 KiB
18Wrong answer0/339ms7380 KiB
19Accepted3/382ms8308 KiB
20Accepted3/376ms8440 KiB
21Accepted3/3266ms8888 KiB
22Wrong answer0/467ms10820 KiB