K`th number
二分答案,check()用two point写
#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long long
#define N 200009
using namespace std;
int n,m;
LL k;
LL a[N],b[N],num,L,R,mid;
bool flag;
inline int read() //读入优化
{
int f=1,p=0;char c=getchar();
while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){p=p*10+c-'0';c=getchar();}
return f*p;
}
bool check(LL x)//小于等于
{
LL tot=0;
int t1=1,t2=m;
while(t1<=n)//two point
{
while(a[t1]*b[t2]>x&&t1<=n&&t2>=1) t2--;
tot+=t2; t1++;
}
return tot<k;//注意判定条件!
}
int main()
{
scanf("%d%d%lld",&n,&m,&k);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(int i=1;i<=m;i++) scanf("%lld",&b[i]);
sort(a+1,a+n+1);sort(b+1,b+m+1);
L=1,R=a[n]*b[m];
while(L<=R)
{
mid=(L+R)>>1;
if(check(mid)) L=mid+1;
else R=mid-1;
}
printf("%lld\n",L);
return 0;
}
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步