161882025-04-14 08:55:32linhnkBányász RPG (40 pont)cpp17Time limit exceeded 36/40400ms1848 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	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/012ms676 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/29ms564 KiB
6Accepted2/221ms820 KiB
7Accepted2/23ms316 KiB
8Accepted2/24ms488 KiB
9Accepted3/31ms316 KiB
10Accepted3/31ms408 KiB
11Accepted3/31ms316 KiB
12Accepted3/31ms316 KiB
13Accepted4/41ms316 KiB
14Accepted4/41ms316 KiB
15Time limit exceeded0/2400ms1332 KiB
16Accepted2/248ms1436 KiB
17Time limit exceeded0/2400ms1336 KiB
18Accepted2/264ms1848 KiB