161892025-04-14 09:15:23linhnkBányász RPG (40 pont)cpp17Time limit exceeded 29/40400ms1076 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, tap=0, a=0, b, t=0, x; 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{
			while(tap<anyu[a].first-tap){
				if(anyu[b].second==0)
				b--;
				if(anyu[b].second<anyu[a].first-tap){
					t=t+2*anyu[b].second;
					tap+=anyu[b].second;
					anyu[b].second=0;
					b--;					
				}
				else{
					anyu[b].second-=(anyu[a].first-tap);
					t=t+2*(anyu[a].first-tap);
					tap+=anyu[a].first-tap;
						
				}
			}
		}
		/*cerr<<anyu[1].second<<endl;
		cerr<<a<<" "<<b<<" "<<tap<<" "<<t<<endl;*/
	}
	cout<<t;
}

SubtaskSumTestVerdictTimeMemory
base29/40
1Accepted0/01ms316 KiB
2Accepted0/013ms316 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/210ms316 KiB
6Accepted2/221ms564 KiB
7Accepted2/23ms316 KiB
8Accepted2/24ms316 KiB
9Accepted3/31ms316 KiB
10Time limit exceeded0/3400ms508 KiB
11Accepted3/31ms316 KiB
12Accepted3/31ms316 KiB
13Accepted4/41ms508 KiB
14Accepted4/41ms400 KiB
15Time limit exceeded0/2381ms568 KiB
16Time limit exceeded0/2381ms1012 KiB
17Wrong answer0/241ms820 KiB
18Time limit exceeded0/2382ms1076 KiB