求逆天代码复杂度
查看原帖
求逆天代码复杂度
1003842
Central_GYM楼主2024/12/7 17:42
#include<bits/stdc++.h>
using namespace std;
const long long N=2e5+5;
long long n,m,jd,cs,p[N],jl=1,cl=1;
struct node{
	long long a,t;
}xijun[N];
bool cmp(node x,node y){
	return x.t<y.t;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>xijun[i].a; 
		p[i]=xijun[i].a;
	}
	for(int i=1;i<=n;i++){
		cin>>xijun[i].t;
		xijun[i].t+=xijun[i].a;
	}
	sort(xijun+1,xijun+1+n,cmp);
	sort(p+1,p+1+n);
	for(int ti=p[1];ti<=1000000000;ti++){
		while(ti==p[jl]){
			jd++;
			jl++;
		}
		while(ti==xijun[cl].t){
			cs++;
			jd--;
			cl++;
		}
		cs*=2;
		if(jd+cs==m){
			cout<<ti;
			return 0;
		}
		if(jd+cs>m){
			cout<<-1;
			return 0; 
		}
	}
	return 0;
}

赛时的逆天代码,有点好奇为什么这个复杂度没被卡掉

2024/12/7 17:42
加载中...