数组a[] , N, 数组b[] , M , 寻找第K大的数ai * bj 。 比较简单
typedef long long LL ; const int maxn = 100008 ; LL a[maxn] , b[maxn] , k , n , m ; int ok(LL x){ LL s = 0 , t ; for(int i = 1 ; i <= n ; i++){ int l = 1 , r = m , mid ; t = 0 ; while(l <= r){ mid = (l + r) >> 1 ; if(x >= a[i] * b[mid]){ t = mid ; l = mid + 1 ; } else r = mid - 1 ; } s += t ; if(s >= k) return 1 ; } return s >= k ; } int main(){ int i ; while(scanf("%lld%lld%lld" , &n ,&m ,&k) != EOF){ k = n*m - k + 1 ; for(i = 1 ; i <= n ; i++) scanf("%lld" , &a[i]) ; for(i = 1 ; i <= m ; i++) scanf("%lld" , &b[i]) ; sort(b+1 , b+1+m) ; LL l , r , mid , s , t ; l = 0 , r = 10000000000LL ; while(l <= r){ mid = (l + r) >> 1 ; if(t = ok(mid)){ s = mid ; r = mid - 1 ; } else l = mid + 1 ; } printf("%lld\n" , s) ; } return 0 ; }
typedef long long LL ; const int maxn = 100008 ; LL a[maxn] , b[maxn] , k , n , m ; int ok(LL x){ LL s = 0 , t ; for(int i = 1 ; i <= n ; i++){ int l = 1 , r = m , mid ; t = 0 ; while(l <= r){ mid = (l + r) >> 1 ; if(x >= a[i] * b[mid]){ t = mid ; l = mid + 1 ; } else r = mid - 1 ; } s += t ; if(s >= k) return 1 ; } return s >= k ; } int main(){ int i ; while(scanf("%lld%lld%lld" , &n ,&m ,&k) != EOF){ k = n*m - k + 1 ; for(i = 1 ; i <= n ; i++) scanf("%lld" , &a[i]) ; for(i = 1 ; i <= m ; i++) scanf("%lld" , &b[i]) ; sort(b+1 , b+1+m) ; LL l , r , mid , s , t ; l = 0 , r = 10000000000LL ; while(l <= r){ mid = (l + r) >> 1 ; if(t = ok(mid)){ s = mid ; r = mid - 1 ; } else l = mid + 1 ; } printf("%lld\n" , s) ; } return 0 ; }