28692023-02-01 10:55:54bzsofiaÓvodacpp11Wrong answer 31/50135ms15236 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>

#define int long long

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;
}

signed 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/03ms1848 KiB
2Accepted0/08ms2324 KiB
3Accepted2/23ms2328 KiB
4Accepted2/23ms2576 KiB
5Accepted2/22ms2728 KiB
6Accepted2/22ms2764 KiB
7Wrong answer0/22ms2892 KiB
8Accepted2/23ms2956 KiB
9Wrong answer0/23ms3208 KiB
10Accepted2/22ms3292 KiB
11Accepted2/23ms3376 KiB
12Accepted2/23ms3392 KiB
13Wrong answer0/24ms3632 KiB
14Accepted3/33ms3844 KiB
15Wrong answer0/317ms4856 KiB
16Wrong answer0/335ms6648 KiB
17Accepted3/350ms7068 KiB
18Wrong answer0/379ms9816 KiB
19Accepted3/393ms9556 KiB
20Accepted3/3103ms10860 KiB
21Accepted3/3115ms11076 KiB
22Wrong answer0/4135ms15236 KiB