85402024-01-21 16:45:49zeytonxBányász RPG (40 pont)cpp17Time limit exceeded 32/40400ms5892 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 it2 = m.begin();

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

		sort(v.rbegin(), v.rend());
		while(m[v[0].sc] != v[0].fs)
		{
			v[0].fs = m[v[0].sc];
			sort(v.rbegin(), v.rend());
		}

		if(v[0].fs > 0)
		{
			v[0].fs--;
			ans += 2;
			remain -= 1;
			exp++;
			m[v[0].sc]--;
		}
	}
	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
base32/40
1Accepted0/03ms2104 KiB
2Time limit exceeded0/0400ms2544 KiB
3Accepted2/23ms2256 KiB
4Accepted2/23ms2440 KiB
5Accepted2/26ms2872 KiB
6Accepted2/28ms3016 KiB
7Accepted2/23ms2752 KiB
8Accepted2/24ms3024 KiB
9Accepted3/33ms3060 KiB
10Accepted3/33ms3072 KiB
11Accepted3/33ms3340 KiB
12Accepted3/317ms3352 KiB
13Accepted4/454ms3392 KiB
14Accepted4/417ms3416 KiB
15Time limit exceeded0/2400ms5100 KiB
16Time limit exceeded0/2345ms5540 KiB
17Time limit exceeded0/2361ms5276 KiB
18Time limit exceeded0/2356ms5892 KiB