// assuming the arrays are sorted in increasing order
pair<int,int> findWindow( int va[MAX], int na, int vb[MAX], int nb, int vc[MAX], int nc) {
pair<int,int> result; // window start, end position
int a,b,c, resultLen = na+nb+nc; // dummy result “infinity”
a = b = c = 0;
do {
int start = min( va[a], min( vb[b], vc[c] ) );
int end = max( va[a], max( vb[b], vc[c] ) );
int len = end-start+1;
if (resultLen > len) {
resultLen = len;
result = make_pair( start, end );
}
if (va[a] <= vb[b]) {
if (va[a] <= vc[c])
a++;
else
c++;
}
else if (vb[b] <= vc[c])
b++;
else
c++;
} while (a < na && b < nb && c < nc);
return result;
}