题解连样例都过不了 这里给出一份相对正确的 欢迎hack
  • 板块P1752 点菜
  • 楼主anideahe
  • 当前回复0
  • 已保存回复0
  • 发布时间2021/7/29 16:33
  • 上次更新2023/11/4 12:45:37
查看原帖
题解连样例都过不了 这里给出一份相对正确的 欢迎hack
178259
anideahe楼主2021/7/29 16:33
#include<queue>
#include<algorithm>
#include<cstdio>
#define ll long long
using namespace std;
const int N=2e5+1;
struct node{ int x,y; }s[N],ans[N];
int n,m,p,q;
int p1[N],p2[N];
priority_queue<node> Q;
bool operator<(node a,node b){ return a.y<b.y; }
bool cmp (int  x,int  y){ return x>y;     }
bool cmp1(node x,node y){ return x.x>y.x; }
bool cmp2(node x,node y){ return x.y<y.y; }
int check(int x){
	ll r=(ll)(n-p-q)*x;
    if(m<=r) return 1;
    int cnt=1,now=1;
    for(int i=1;i<=p;i=-~i){
        while(s[now].x>=p1[i]&&now<=m) Q.push(s[now++]);
        for(int j=1;!Q.empty()&&j<=x;++j) Q.pop();
    }
    while(!Q.empty()){
    	ans[cnt++]=Q.top();
    	Q.pop();
    }
    while(now<=m) ans[cnt++]=s[now],now++;
    cnt--;now--; 
    sort(ans+1,ans+cnt+1,cmp2);
    int cnt1=1;
    for(int i=1;i<=q;i=-~i){
    	for(int j=1;j<=x&&cnt1<=cnt&&ans[cnt1].y<=p2[i];j=-~j) cnt1++;
    	if(cnt1>cnt||ans[cnt1].y>p2[i]) cnt1--;
	}
	if(!q) cnt1--;
    if(cnt1<cnt-(n-p-q)*x) return 0;
    return 1;
}
int main(){
    scanf("%d%d%d%d",&n,&m,&p,&q);
	for(int i=1;i<=m;i=-~i)
        scanf("%d%d",&s[i].x,&s[i].y);
    sort(s+1,s+m+1,cmp1);
    for(int i=1;i<=p;i=-~i)scanf("%d",&p1[i]);
    sort(p1+1,p1+p+1,cmp);
    for(int i=1;i<=q;i=-~i)scanf("%d",&p2[i]);
    sort(p2+1,p2+q+1);
    int l=1,r=m,ans=-1;
    while(l<=r){
        int mid=(l+r)>>1;	
        if(check(mid)) r=mid-1,ans=mid;
        else l=mid+1;
    }
    printf("%d",ans);
}
2021/7/29 16:33
加载中...