1540: K large number of two array elements multiplied by the K large (binary answer + input and output optimization)

Source: Internet
Author: User

1540: K Large number
Time Limit:10 Sec Memory limit:128 MB
submit:104 Solved:6
[Submit] [Status] [Web Board]
Description

There are two sequences, a, B, and their lengths are N and M respectively, so what is the K element after multiplying the elements in the two sequence by the N*M elements from the large to the small?

Input

The first behavior of the input is a positive integer t (t<=10), which represents a total of T-Group test data.

The first line of each set of test data has three positive integers n,m and K (1<=n, M<=100000,1<=k<=n*m), respectively, representing the length of a sequence, the length of the b sequence, and the subscript of the element being asked. The second behavior n a positive integer represents sequence a. The third behavior m positive integers represent sequence B. The size of all elements in the sequence satisfies [1,100000].

Output

For each set of test data, the output line contains an integer representing the number of elements of the K-large.

Sample Input
3
3 2 3
1 2 3
1 2
2 2 1
1 1
1 1
2 2 4
1 1
1 1
Sample Output
3
1

1

#include <bits/stdc++.h>using namespace Std;template<class t>inline T Read (t&x) {char C;    while ((C=getchar ()) <=32) if (c==eof) return 0;    BOOL Ok=false;    if (c== '-') Ok=true,c=getchar ();    for (x=0; c>32; C=getchar ()) x=x*10+c-' 0 ';    if (OK) x=-x; return 1;} Template<class t> inline T read_ (t&x,t&y) {return read (x) &&read (y);} Template<class t> inline T read__ (t&x,t&y,t&z) {return read (x) &&read (y) &&read (z);}    Template<class t> inline void Write (T x) {if (x<0) Putchar ('-'), x=-x;    if (x<10) putchar (x+ ' 0 '); else write (X/10), Putchar (x%10+ ' 0 ');}    Template<class t>inline void Writeln (T x) {write (x); Putchar (' \ n ');} -------ZCC IO template------const int MAXN=1E5+1;CONST double inf=999999999; #define Lson (rt<<1), L,m#define Rson (rt<<1|1), M+1,r#define M ((l+r) >>1) #define for (i,t,n) for (int i= (t);i< (n); i++) typedef long Long LL; typedef double DB;TYPEDEF pair<int,int> P; #define BUG printf ("---\ n"); #define MOD 1000000007int a[maxn],b[maxn];int n,m,k;bool pan (LL num) {int    cnt=0; for (int i=0;i<n;i++) cnt+=m-(Upper_bound (B,b+m,num/a[i])-B);//Find out if the number of elements larger than num//printf ("Num=%lld cnt=%d\n", n    UM,CNT); return cnt>k-1;}    void Slove () {ll l= (LL) a[0]*b[0];        ll H= (LL) a[n-1]*b[m-1];//between the maximum minimum value of the two-part answer while (L&LT;=H) {ll mid= (LL) (L+H)/2;        if (Pan (mid)) l=mid+1;    else h=mid-1; } writeln (l);}    int main () {int T;    Freopen ("In.txt", "R", stdin);    Read (T);        while (t--) {read__ (n,m,k);        for (i,0,n) read (A[i]);        for (i,0,m) read (B[i]);        Sort (a,a+n);        Sort (b,b+m);    Slove (); } return 0;}

1540: K large number of two array elements multiplied by the K large (binary answer + input and output optimization)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.