-
Title Description:
-
Given two integer arrays A and B. We add the element 22 in a and B to get the array C.
For example A is [1,2],b] [3,4]. Then the array c that is added by element 22 in A and B is [4,5,5,6].
Now give you the array A and B, for the sum of the array C, which is added by A and b 22, the small number of K.
-
Input:
-
The input may contain multiple test cases.
For each test case, enter the first behavior of three integers m,n, K (1<=m,n<=100000, 1<= k <= n *m): The n,m represents the length of the array A and b that will be entered.
The next two lines, respectively, are the number of M and N, representing the elements in arrays A and B. The array element range is [0,1e9].
-
Output:
-
corresponding to each test case,
Outputs the small number of k in the array C obtained by adding the element 22 in a and B.
-
Sample input:
-
2 2 31 23 43 3 41 2 73 4 5
-
Sample output:
-
56
-
Source:
-
Google face questions
#include <stdio.h> #include <stdlib.h>long long A[100000];long long B[100000];long long n,m,i,j,k;int Compare (const void * p, const void * q) {return * (Long long *) P-* (Long long *) q; } A long long cal (Long Long v) {Long long add=0,j=m-1; for (i=0;i<n;i++) {while (j>=0&& (A[i]+b[j]) >v) j--; add+= (j+1); } return add;} Long long Ll,long long Rr,long long k) {Long long mid; while (LL<=RR) {mid= (LL+RR)/2; if (K<=cal (mid)) rr=mid-1; else ll=mid+1; } return ll; int main () {Long long ll,rr; while (scanf ("%lld%lld%lld", &n,&m,&k)!=eof) {for (i=0;i<n;i++) {scanf ("%lld", &a[i]); }qsort (A, N, sizeof (long long), compare); for (i=0;i<m;i++) {scanf ("%lld", &b[i]); }qsort (b, M, sizeof (long long), compare); LL=A[0]+B[0]; RR=A[N-1]+B[M-1]; printf ("%lld\n", Find (Ll,rr,k)); } return 0;}
Nine degrees oj-topic 1534: K small number in the array