85252024-01-21 08:38:06MagyarKendeSZLGÓvodacpp17Hibás válasz 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 << ' ';
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base33/50
1Elfogadva0/03ms1960 KiB
2Elfogadva0/04ms2548 KiB
3Elfogadva2/23ms2356 KiB
4Elfogadva2/23ms2568 KiB
5Elfogadva2/23ms2716 KiB
6Elfogadva2/22ms2708 KiB
7Hibás válasz0/22ms2708 KiB
8Elfogadva2/23ms2936 KiB
9Elfogadva2/22ms2936 KiB
10Elfogadva2/23ms3064 KiB
11Elfogadva2/22ms3092 KiB
12Elfogadva2/23ms3220 KiB
13Hibás válasz0/23ms3344 KiB
14Elfogadva3/33ms3340 KiB
15Hibás válasz0/314ms4352 KiB
16Hibás válasz0/3118ms5440 KiB
17Elfogadva3/327ms5980 KiB
18Hibás válasz0/339ms7380 KiB
19Elfogadva3/382ms8308 KiB
20Elfogadva3/376ms8440 KiB
21Elfogadva3/3266ms8888 KiB
22Hibás válasz0/467ms10820 KiB