28682023-02-01 10:54:12bzsofiaÓvodacpp11Wrong answer 31/50116ms9812 KiB
// ovoda.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

//#include <fstream>
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

//ifstream fin("ovoda.in");

int i, n, m, ures, szerep, sir;
deque <int> maradek;

struct adat1
{
    int fer;
    bool van=0;
};

struct adat2
{
    int konny, cel, poz, lett;
};

bool comp1 (adat2 a, adat2 b)
{
    return a.konny > b.konny;
}

bool comp2(adat2 a, adat2 b)
{
    return a.poz < b.poz;
}

int main()
{
    cin >> n >> m;
    vector <adat1> szin(m + 1);
    vector <adat2> gyerek(n + 1);
    for (i = 1; i <= m; ++i)
    {
        cin >> szin[i].fer;
    }

    for (i = 1; i <= n; ++i)
    {
        cin >> gyerek[i].cel;
        gyerek[i].poz = i;
    }

    for (i = 1; i <= n; ++i)
    {
        cin >> gyerek[i].konny;
    }

    sort(gyerek.begin() + 1, gyerek.end(), comp1);

    ures = m;
    for (i = 1; i <= n; ++i)
    {
        szerep = gyerek[i].cel;
        if (szin[szerep].fer && n-i>=ures)
        {
            if (!szin[szerep].van)
            {
                szin[szerep].van = 1;
                --ures;
            }
            gyerek[i].lett = szerep;
            --szin[szerep].fer;
        }
        else
        {
            --ures;
            maradek.push_back(i);
            sir += gyerek[i].konny;
        }
    }

    for (i = 1; i <= m; ++i)
    {
        if (!szin[i].van)
        {
            szin[i].van = 1;
            --szin[i].fer;
            gyerek[maradek.front()].lett = i;
            maradek.pop_front();
        }
    }

    i = 1;
    while (!maradek.empty() && i<=m)
    {
        while (!maradek.empty() && szin[i].fer)
        {
            --szin[i].fer;
            gyerek[maradek.front()].lett = i;
            maradek.pop_front();
        }
        ++i;
    }

    sort(gyerek.begin() + 1, gyerek.end(), comp2);

    cout << sir << "\n";
    for (i = 1; i <= n; ++i)
    {
        cout << gyerek[i].lett << " ";
    }

    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base31/50
1Accepted0/03ms1936 KiB
2Accepted0/07ms2416 KiB
3Accepted2/23ms2280 KiB
4Accepted2/23ms2512 KiB
5Accepted2/23ms2600 KiB
6Accepted2/23ms2800 KiB
7Wrong answer0/23ms3156 KiB
8Accepted2/22ms3180 KiB
9Wrong answer0/23ms3088 KiB
10Accepted2/23ms3356 KiB
11Accepted2/23ms3488 KiB
12Accepted2/23ms3588 KiB
13Wrong answer0/23ms3580 KiB
14Accepted3/34ms3840 KiB
15Wrong answer0/314ms4108 KiB
16Wrong answer0/330ms5232 KiB
17Accepted3/343ms5296 KiB
18Wrong answer0/370ms6608 KiB
19Accepted3/379ms6528 KiB
20Accepted3/387ms7188 KiB
21Accepted3/3100ms7780 KiB
22Wrong answer0/4116ms9812 KiB