113592024-08-24 09:21:04GervidBányász RPG (40 pont)cpp17Wrong answer 36/4032ms1016 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{
	iostream::sync_with_stdio(0);
	cin.tie(0);

	int n, i;
	cin >> n;

	vector<pair<int, int>> resources(n);
	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());

	int xp = 0, ans = 0, twice, once, j = n-1, need;

	for (i = 0; i < n && i <= j; i++)
	{
		while (resources[i].first > xp && i < j)
		{
			twice = min(resources[j].second, max(0, (resources[i].first - xp)));
			resources[j].second -= twice;

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

			if (resources[j].second == 0) j--;
		}

		twice = min(resources[i].second, max(0, (resources[i].first - xp)));
		once = resources[i].second - twice;

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

	cout << ans;
}
SubtaskSumTestVerdictTimeMemory
base36/40
1Accepted0/02ms356 KiB
2Accepted0/07ms628 KiB
3Accepted2/23ms500 KiB
4Accepted2/23ms356 KiB
5Accepted2/27ms632 KiB
6Accepted2/212ms632 KiB
7Accepted2/23ms484 KiB
8Accepted2/24ms356 KiB
9Accepted3/32ms364 KiB
10Accepted3/32ms356 KiB
11Accepted3/33ms228 KiB
12Accepted3/33ms228 KiB
13Accepted4/43ms376 KiB
14Accepted4/42ms232 KiB
15Wrong answer0/218ms1012 KiB
16Accepted2/225ms1016 KiB
17Wrong answer0/220ms760 KiB
18Accepted2/232ms1016 KiB