54162023-05-16 10:22:25TortelliniJrBányász RPG (40 pont)cpp17Accepted 40/4032ms5336 KiB
#include <stdio.h>
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0), cin.sync_with_stdio(0);
	int n;
	cin >> n;
	vector<array<int, 2>> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i][0];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> v[i][1];
	}
	sort(v.begin(), v.end());
	int l = 0, r = n - 1;
	ll xp = 0;
	ll time = 0;
	while (l <= r) {
		if (v[l][0] <= xp) {
			time += v[l][1];
			xp += v[l][1];
			v[l][1] = 0;
			l++;
		}
		else {
			time += 2;
			xp++;
			v[r][1]--;
			if (v[r][1] == 0)
				r--;
		}
	}
	cout << time;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1700 KiB
2Accepted0/08ms2176 KiB
3Accepted2/23ms2140 KiB
4Accepted2/23ms2356 KiB
5Accepted2/27ms2792 KiB
6Accepted2/212ms3388 KiB
7Accepted2/23ms2948 KiB
8Accepted2/24ms3028 KiB
9Accepted3/32ms2888 KiB
10Accepted3/33ms3020 KiB
11Accepted3/33ms3248 KiB
12Accepted3/33ms3484 KiB
13Accepted4/43ms3696 KiB
14Accepted4/43ms3848 KiB
15Accepted2/218ms4732 KiB
16Accepted2/224ms4944 KiB
17Accepted2/220ms4820 KiB
18Accepted2/232ms5336 KiB