85392024-01-21 16:44:17zeytonxBányász RPG (40 pont)cpp17Time limit exceeded 32/40398ms9412 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});

	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;
		}

		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/03ms1828 KiB
2Time limit exceeded0/0398ms3008 KiB
3Accepted2/23ms2424 KiB
4Accepted2/23ms2520 KiB
5Accepted2/26ms3068 KiB
6Accepted2/28ms3648 KiB
7Accepted2/23ms3664 KiB
8Accepted2/24ms3940 KiB
9Accepted3/33ms4164 KiB
10Accepted3/33ms4036 KiB
11Accepted3/33ms4040 KiB
12Accepted3/317ms4092 KiB
13Accepted4/454ms4288 KiB
14Accepted4/417ms4148 KiB
15Time limit exceeded0/2354ms6444 KiB
16Time limit exceeded0/2365ms7496 KiB
17Time limit exceeded0/2361ms7836 KiB
18Time limit exceeded0/2361ms9412 KiB