85452024-01-21 16:55:53zeytonxBányász RPG (40 pont)cpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/03ms1832 KiB
2Elfogadva0/012ms4564 KiB
3Elfogadva2/23ms2232 KiB
4Elfogadva2/23ms2476 KiB
5Elfogadva2/24ms2916 KiB
6Elfogadva2/28ms3188 KiB
7Elfogadva2/23ms3236 KiB
8Elfogadva2/24ms3464 KiB
9Elfogadva3/33ms3476 KiB
10Elfogadva3/33ms3600 KiB
11Elfogadva3/33ms3680 KiB
12Elfogadva3/33ms3892 KiB
13Elfogadva4/43ms3988 KiB
14Elfogadva4/43ms4108 KiB
15Elfogadva2/229ms9056 KiB
16Elfogadva2/237ms9736 KiB
17Elfogadva2/232ms9276 KiB
18Elfogadva2/248ms10676 KiB