2020 CCPC Wannafly Winter Camp Day1F 乘法(二分)
阿新 • • 發佈:2020-11-20
暴力二分答案即可獲得正解,注意邊界問題
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,int> pll; const int N=1e6+10; ll n,m,k; ll a[N],b[N]; bool check(ll x){ ll cnt=0; int i; for(i=1;i<=m;i++){ if(b[i]==0) cnt+=(x<0)?n:0; if (b[i]<0View Code) cnt+=lower_bound(a+1, a+n+1, ceil((double)x / b[i]))-(a + 1); if (b[i]>0) cnt+=n-((upper_bound(a+1, a + n + 1, floor((double)x/b[i])))-(a+1)); } return cnt<=k; } int main(){ ios::sync_with_stdio(false); cin>>n>>m>>k; int i,j; k--; for(i=1;i<=n;i++) cin>>a[i]; for(i=1;i<=m;i++) cin>>b[i]; sort(a+1,a+1+n); sort(b+1,b+1+m); ll l=-1e13,r=1e13; while(l<r){ ll mid=l+r>>1; if(check(mid)) r=mid; else l=mid+1; } cout<<l<<endl; return 0; }