90 WA on test#7 求调
  • 板块P1752 点菜
  • 楼主zhc223
  • 当前回复1
  • 已保存回复1
  • 发布时间2025/1/25 18:31
  • 上次更新2025/1/25 22:31:53
查看原帖
90 WA on test#7 求调
1381037
zhc223楼主2025/1/25 18:31
#include<bits/stdc++.h>
using namespace std;
#define int long long
long long P,Q,n,m,p[50005],q[50005];
pair<int,int> pr[200005],pa[200005];
bool cmp(pair<int,int> x,pair<int,int> y){return x.first>y.first;}
bool cmp2(int x,int y){return x>y;}
bool cmp3(pair<int,int> x,pair<int,int> y){return x.second<y.second;}
bool check(int x){
	priority_queue<pair<int,int> > pq1;
	int sum=0,l=1;
	for(int i=1;i<=P;i++){
		while(pa[l].first>=p[i] && l<=m) pq1.push({pa[l].second,l}),l++;
		int y=0;
		while(!pq1.empty() && y<x) y++,pq1.pop(),sum++;
	}
	int k=0;
	while(!pq1.empty()) pr[++k]=pa[pq1.top().second],pq1.pop();
	for(int i=l;i<=m;i++) pr[++k]=pa[i];
	sort(pr+1,pr+k+1,cmp3),l=1;
	int y=0;
	for(int i=1;i<=Q;i++){
	    while(pr[l].second<=q[i] && l<=k) y++,l++;
	}
	sum+=min(y,Q*x)+(n-P-Q)*x;
	return sum>=m; 
}
int erfen(){
	int l=1,r=m;
	while(l<r){
		if(check((l+r)/2)) r=(l+r)/2;
		else l=(l+r)/2+1;
	}
	return l;
}
signed main(){
    cin>>n>>m>>P>>Q;
    for(int i=1;i<=m;i++) cin>>pa[i].first>>pa[i].second;
    sort(pa+1,pa+m+1,cmp);
    for(int i=1;i<=P;i++) cin>>p[i];
    sort(p+1,p+P+1,cmp2);
    for(int i=1;i<=Q;i++) cin>>q[i];
    sort(q+1,q+Q+1);
    if(!check(m)) cout<<-1;
    else cout<<erfen();
    return 0;
}

2025/1/25 18:31
加载中...