public double findKth(int[] A, int[] B, int K) {
        if (A.length > B.length)
            return findKth(B, A, K);
        if (A.length == 0)
            return B[K];
        if (K == 0)
            return A[0] < B[0] ? A[0] : B[0];
        int a = Math.min(A.length, K / 2);
        int b = K - a;
        if (A[a] > B[b])
            return findKth(A, Arrays.copyOfRange(B, b, B.length), K - a);
        else if (A[a] < B[b])
            return findKth(Arrays.copyOfRange(A, a, A.length), B, K - b);
        else
            return A[a];

    }