nlogn for drives and mlogm for keyboard. So, if you sort both independently, shouldn't it be mlogm+nlogn , instead of (m+n)log(m+n) ?