162322025-04-14 18:47:42linhnkBányász RPG (40 pont)cpp17Time limit exceeded 36/40400ms1076 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, tap=0, a=0, b, t=0; cin>>n; b=n-1;
	vector<pair<int, int>> anyu(n);
	for(int i=0; i<n; i++){
		cin>>anyu[i].first;
	}
	for(int i=0; i<n; i++){
		cin>>anyu[i].second;
	}
	sort(anyu.begin(), anyu.end());
	while(a<=b){
		if(anyu[a].first<=tap){
			t+=anyu[a].second;
			tap+=anyu[a].second;
			a++;
		}
		else{
			if(anyu[b].second==0)
			b--;
			t+=2;
			anyu[b].second--;
			tap++;
		}
	}
	cout<<t;
}
SubtaskSumTestVerdictTimeMemory
base36/40
1Accepted0/01ms316 KiB
2Accepted0/06ms316 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/24ms556 KiB
6Accepted2/29ms564 KiB
7Accepted2/22ms316 KiB
8Accepted2/22ms316 KiB
9Accepted3/31ms512 KiB
10Accepted3/31ms508 KiB
11Accepted3/31ms496 KiB
12Accepted3/31ms316 KiB
13Accepted4/41ms316 KiB
14Accepted4/41ms316 KiB
15Time limit exceeded0/2400ms824 KiB
16Accepted2/221ms820 KiB
17Time limit exceeded0/2400ms672 KiB
18Accepted2/228ms1076 KiB