DPAIRS TLE JAVA

Each of A or B element is represented by a List element of size 2. When I sort the A’s and B’s(using Arrays.sort) and print N+M-1 lines, I am getting TLE for each test case in subtask#2. Moreover, even if I don’t perform any sorting and just print N+M-1 lines after reading and creating A’s and B’s still I get TLE in most of the cases in subtask#2. Can anyone help me here? Do I have to share my code?
PS: I am using the FastReader class to read inputs.