90分求调
查看原帖
90分求调
757101
junee楼主2024/4/19 23:02

第九个点输出5000,答案2500

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1e5+10;
typedef pair<int,int>PII;
PII p1[N],p2[N];
int n,m1,m2;
int num1[N],num2[N];
bool cmp(PII a,PII b){
	return a.first<b.first;
}
void calc(PII a[],int m,int f){
	int t[N],tt=1;
	memset(t,0,sizeof t);
	int tot[N];
	memset(tot,0,sizeof tot);
	for(int i=1;i<=m;i++){
		int b=1;
		for(int j=1;j<=tt;j++){
			if(a[i].first>t[j]){
				t[j]=a[i].second;
				b=0;
				tot[j]+=1;
				break;
			}
		}
		if(b){
			t[++tt]=a[i].second;
			tot[tt]=1;
		}
	}
	if(f==1){
		for(int i=1;i<=m;i++){
			num1[i]=num1[i-1]+tot[i];
		}
	}
	else if(f==2){
		for(int i=1;i<=m;i++){
			num2[i]=num2[i-1]+tot[i];
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	if(n>=m1+m2){
		cout<<n;
		return 0; 
	}
	cin>>n>>m1>>m2;
	for(int i=1;i<=m1;i++){
		int a,b;
		cin>>a>>b;
		p1[i]={a,b};
	}
	for(int i=1;i<=m2;i++){
		int a,b;
		cin>>a>>b;
		p2[i]={a,b};
	}
	sort(p1+1,p1+1+m1,cmp);
	sort(p2+1,p2+1+m2,cmp);
	calc(p1,m1,1);
	calc(p2,m2,2);
	int ans=0;
	for(int i=0;i<=n;i++){
		ans=max(ans,num1[i]+num2[n-i]);
	}
	cout<<ans;
	return 0;
}
2024/4/19 23:02
加载中...