93292024-02-20 14:26:57ananászÓvodacpp17Hibás válasz 28/50120ms14548 KiB
// ovoda.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct szerep {
	int akt_db;
	int max_db;
};
struct gyerek {
	int kivant;
	int siras;
	int kapott;
	int id;
};
bool rendez(gyerek gy1, gyerek gy2) {
	return gy1.siras > gy2.siras;
}
bool rendez2(gyerek gy1, gyerek gy2) {
	return gy1.id< gy2.id;
}
int main()
{
	int N, K;
	cin >> N >> K;
	vector<szerep>szerepek(K);
	int x;
	for (int i = 0; i < K; i++)
	{
		cin >> x;
		szerepek[i].max_db = x;
		szerepek[i].akt_db = 0;
	}
	vector<gyerek>gyerekek(N);
	for (int i = 0; i < N; i++)
	{
		cin >> x;
		gyerekek[i].kivant = x;
		gyerekek[i].kapott = -1;
		gyerekek[i].id = i;
	}
	for (int i = 0; i < N; i++)
	{
		cin >> x;
		gyerekek[i].siras = x;
	}
	sort(gyerekek.begin(), gyerekek.end(), rendez);
	int siras = 0;
	for (int i = 0; i < N; i++)
	{
		if (szerepek[gyerekek[i].kivant-1].akt_db < szerepek[gyerekek[i].kivant-1].max_db)
		{
			szerepek[gyerekek[i].kivant-1].akt_db++;
			gyerekek[i].kapott = gyerekek[i].kivant;
		}
		else
		{
			siras += gyerekek[i].siras;
		}
	}
	cout << siras<<endl;
	int id = 0;
	string sep = "";
	sort(gyerekek.begin(), gyerekek.end(), rendez2);
	for (int i = 0; i < N; i++)
	{
		if (gyerekek[i].kapott==-1)
		{
			while (szerepek[id].max_db == szerepek[id].akt_db)
			{
				id++;
			}
			//gyerekek[i].kapott=id+1;
			szerepek[id].akt_db++;
			cout <<sep<< id + 1;
		}
		else
		{
			cout << sep << gyerekek[i].kapott;
		}
		sep = " ";
	}
}

// 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base28/50
1Elfogadva0/03ms1808 KiB
2Hibás válasz0/07ms2152 KiB
3Elfogadva2/23ms2224 KiB
4Részben helyes1/23ms2436 KiB
5Elfogadva2/23ms2652 KiB
6Elfogadva2/23ms2868 KiB
7Hibás válasz0/23ms3072 KiB
8Részben helyes1/23ms3200 KiB
9Elfogadva2/23ms3392 KiB
10Elfogadva2/23ms3476 KiB
11Elfogadva2/23ms3608 KiB
12Részben helyes1/23ms3628 KiB
13Hibás válasz0/23ms3768 KiB
14Elfogadva3/34ms4004 KiB
15Hibás válasz0/314ms4656 KiB
16Hibás válasz0/332ms5628 KiB
17Elfogadva3/346ms6464 KiB
18Hibás válasz0/371ms8388 KiB
19Elfogadva3/382ms9176 KiB
20Elfogadva3/392ms10428 KiB
21Részben helyes1/3107ms12204 KiB
22Hibás válasz0/4120ms14548 KiB