113632024-08-26 17:10:53GervidBányász RPG (40 pont)cpp17Hibás válasz 36/4032ms1128 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main()//1(int n, vector<pair<int, int>> resources)
{
	iostream::sync_with_stdio(0);
	cin.tie(0);

	//int i;
	int n, i;
	cin >> n;

	vector<pair<int, int>> resources(n); // {xp treshold, needed amount}
	for (i = 0; i < n; i++)
	{
		cin >> resources[i].first;
	}
	for (i = 0; i < n; i++)
	{
		cin >> resources[i].second;
	}

	sort(resources.begin(), resources.end()); //sort by the xp tresholds

	int xp = 0, ans = 0, j = n-1;

	for (i = 0; i < n && i <= j; i++)
	{
		while (xp < resources[i].first && j > i) //while not enough xp for next easiest, do the hardest
		{
			int twice = min(resources[j].second, resources[i].first - xp); //get as much as (there is from the material/needed for the next xp treshold)
			resources[j].second -= twice; //document the changes

			xp += twice;
			ans += 2 * twice;

			if (resources[j].second == 0) j--; //get the hardest not completed material
		}

		int twice = min(resources[i].second, max(0, (resources[i].first - xp))); //get as much as (needed for the xp treshold/there is from the material)
		int once = resources[i].second - twice; //if there is a remainder, we get it twice as fast

		xp += once + twice;
		ans += once + 2 * twice;
	}

	//return(ans);
	cout << ans;
}

RészfeladatÖsszpontTesztVerdiktIdőMemória
base36/40
1Elfogadva0/02ms400 KiB
2Elfogadva0/08ms488 KiB
3Elfogadva2/23ms400 KiB
4Elfogadva2/23ms548 KiB
5Elfogadva2/27ms488 KiB
6Elfogadva2/212ms760 KiB
7Elfogadva2/24ms488 KiB
8Elfogadva2/24ms364 KiB
9Elfogadva3/33ms360 KiB
10Elfogadva3/33ms632 KiB
11Elfogadva3/33ms360 KiB
12Elfogadva3/33ms360 KiB
13Elfogadva4/43ms504 KiB
14Elfogadva4/43ms396 KiB
15Hibás válasz0/219ms744 KiB
16Elfogadva2/225ms1004 KiB
17Hibás válasz0/220ms888 KiB
18Elfogadva2/232ms1128 KiB