Hi , obviously [this problem](https://jollybeeoj.com/problem/view/191) can be solved in O(N*M) with help of an array for counting, because numbers are <=1000 . but what is the best algorithm for solving this problem when numbers are <=1e9 ?↵
↵
I wrote this [code](http://ideone.com/Xiz5fvxOCRdc) that works in O( N*M*log(N*M) ) but it got TimeLimit ( in 1second ) . How can we reduce this complexity ?↵
↵
UPD : sorry , I linked to wrong source code. fixed.
↵
I wrote this [code](http://ideone.com/
↵
UPD : sorry , I linked to wrong source code. fixed.