Submission #1212011

#TimeUsernameProblemLanguageResultExecution timeMemory
1212011kokoxuyaBikeparking (EGOI24_bikeparking)C++20
100 / 100
304 ms37992 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define ss second
#define ff first
#define piii pair<int,pii>
#define debu(x) (cerr << #x  << " = "<< x << "\n")
#define debu2(x,y) (cerr << #x  << " = "<< x << " " << #y << " = " << y << "\n")
#define debu3(x,y,z) (cerr << #x  << " = "<< x << " " << #y << " = " << y << " " << #z << " = " << z<< "\n")
#define bitout(x,y) {\
	cerr << #x << " : ";\
	for (int justforbits = y; justforbits >=0; justforbits--)cout << (((1 << justforbits) & x)>=1);\
	cout << "\n";\
}
#define rangeout(j,rangestart,rangeend) {\
	cerr << "outputting" << #j<< ":\n";\
	for (int forrang = rangestart; forrang <= rangeend; forrang++)cerr << j[forrang] << " ";\
}
#define c1 {cout << "Checkpoint 1! \n\n";cout.flush();}
#define c2 {cout << "Checkpoint 2! \n\n";cout.flush();}
#define c3 {cout << "Checkpoint 3! \n\n";cout.flush();}
#define c4 {cout << "Checkpoint 4! \n\n";cout.flush();}


signed main()
{
    int t1,t2,t3,t4;
    mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;cin>>n;
	set<pii>slots,tiers,tiers2;
	int ans=0;
	for(int a=1;a<=n;a++)
	{
		cin>>t1;
		if(t1!=0)slots.insert(mp(a,t1));
	}
	for(int a=1;a<=n;a++)
	{
		cin>>t1;
		if(t1!=0)tiers.insert(mp(a,t1));
	}
	
	for(auto it=tiers.begin();it!=tiers.end();it++)
	{
		int lvl=(*it).ff,num=(*it).ss;
		auto oth=slots.lower_bound(mp(lvl,0));
		//debu2(lvl,num);
		while(!slots.empty()&&oth!=slots.begin())
		{
			oth--;
			int othno=(*oth).ss,othlvl=(*oth).ff;
			ans+=min(othno,num);
			slots.erase(oth);
			if(othno>num)slots.insert(mp(othlvl,othno-num));
			num=max(num-othno,0ll);
			//c1;
			//debu2(othno,num);
			if(num==0)break;
			oth=slots.lower_bound(mp(lvl,0));
		}
		if(num!=0)tiers2.insert(mp(lvl,num));
	}
	
	for(auto it=tiers2.begin();it!=tiers2.end();it++)
	{
		int lvl=(*it).ff,num=(*it).ss;
		auto oth=slots.lower_bound(mp(lvl,0));
		if(oth!=slots.end()&&(*oth).ff==lvl)
		{
			int othno=(*oth).ss,othlvl=(*oth).ff;
			slots.erase(oth);
			if(othno>num)slots.insert(mp(othlvl,othno-num));
			num=max(num-othno,0ll);
			//c2;
			//debu2(othno,num);
			if(num==0)break;
		}
		ans-=num;		
	}
	cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...