85242024-01-21 08:20:21MagyarKendeSZLGÓvodacpp17Wrong answer 28/5067ms15716 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

int main() {
    speed;

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

    vector<int> roleS(K), wantS(K);
    cinv(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 (roleS[kid] > 0) {
            roleS[kid]--;
            wantS[kid]--;
            result[i] = kid;
            continue;
        }

        total_cry += cry;

        for (int j = 0; j < K; j++) {
            if (wantS[j] < roleS[j]) {
                roleS[j]--;
                result[i] = j;
                break;
            }
        }
    }

    cout << total_cry << '\n';
    for (int x : result) cout << x + 1 << ' ';
}
SubtaskSumTestVerdictTimeMemory
base28/50
1Accepted0/03ms1832 KiB
2Wrong answer0/04ms2484 KiB
3Accepted2/23ms2544 KiB
4Partially correct1/23ms2524 KiB
5Accepted2/23ms2596 KiB
6Accepted2/23ms2668 KiB
7Wrong answer0/23ms2768 KiB
8Partially correct1/23ms2904 KiB
9Accepted2/23ms3016 KiB
10Accepted2/23ms3232 KiB
11Accepted2/23ms3324 KiB
12Partially correct1/23ms3332 KiB
13Wrong answer0/23ms3508 KiB
14Accepted3/33ms3620 KiB
15Wrong answer0/39ms4552 KiB
16Wrong answer0/341ms5836 KiB
17Accepted3/327ms6952 KiB
18Wrong answer0/339ms8756 KiB
19Accepted3/348ms10804 KiB
20Accepted3/357ms11792 KiB
21Partially correct1/367ms13116 KiB
22Wrong answer0/467ms15716 KiB