#define OUTPUT (x, y) \
if ( ++c == k) { \
printf("%d %d\n", x, y);\
return;\
}
void found(int[]a, int m, int[] b, int n, int k)
{
int i=0, j=0;
int c=0;
while(iOUTPUT(a[i], b[j]);
if (i==m-1 && jj++;
else if (ji++;
else if (a[i]+ b[j+1] > a[i+1]+b[j]) {
int index = j+1;
while(index a[i+1]+b[j]) {
OUTPUT(a[i], b[index]);
index++;
}
i++;
} else { // a[i]+ b[j+1] <= a[i+1]+b[j]
int index = i+1;
while(index a[i]+b[j+1]) {
OUTPUT(a[index], b[j]);
index++;
}
j++;
}
}
}