85452024-01-21 16:55:53zeytonxBányász RPG (40 pont)cpp17Accepted 40/4048ms10676 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pll pair<long, long>
#define endl "\n"
#define fs first
#define sc second
#define vll vector<ll>

void solve()
{
	ll n;
	cin >> n;
	map<ll,ll> m;
	vll a(n);
	ll remain = 0, ans = 0, exp = 0;
	for(ll i = 0; i < n; i++)
		cin >> a[i];
	for(ll i = 0; i < n; i++)
	{
		ll inp;
		cin >> inp;
		remain += inp;
		m[a[i]] += inp;
	}
	vector<pll> v;
	for(auto i : m)
		v.push_back({i.sc, i.fs});

	auto max_it = m.begin();
	ll max_v = -1;

	while(remain > 0)
	{
		for(auto it = m.begin(); it != m.end(); it++)
		{
			if((*it).sc == 0)
				continue;
			if((*it).fs > exp)
				break;
			ans += (*it).sc;
			remain -= (*it).sc;
			exp += (*it).sc;
			(*it).sc = 0;
		}

		if((*max_it).sc != max_v)
			for(auto it = m.begin(); it != m.end(); it++)
			{
				if((*it).sc > max_v)
				{
					max_v = (*it).sc;
					max_it = it;
				}
			}

		if((*max_it).sc > 0)
		{
			(*max_it).sc--;
			ans += 2;
			remain -= 1;
			exp++;
			max_v--;
		}
	}
	cout << ans << endl;
}

int main() 
{
	cin.tie(NULL); cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	ll t = 1;
	//cin >> t;
	while(t--) solve();
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1832 KiB
2Accepted0/012ms4564 KiB
3Accepted2/23ms2232 KiB
4Accepted2/23ms2476 KiB
5Accepted2/24ms2916 KiB
6Accepted2/28ms3188 KiB
7Accepted2/23ms3236 KiB
8Accepted2/24ms3464 KiB
9Accepted3/33ms3476 KiB
10Accepted3/33ms3600 KiB
11Accepted3/33ms3680 KiB
12Accepted3/33ms3892 KiB
13Accepted4/43ms3988 KiB
14Accepted4/43ms4108 KiB
15Accepted2/229ms9056 KiB
16Accepted2/237ms9736 KiB
17Accepted2/232ms9276 KiB
18Accepted2/248ms10676 KiB