### WarpSpeed's blog

By WarpSpeed, history, 4 years ago, ,

This is a very strange incident. And I'll not be exaggerating when I say this but, I truly am bewildered by it.

While solving the following question : http://codeforces.com/problemset/problem/614/A

I got a WA on Test case 39. When I decided to run the same code on Ideone, this is what I found:

Case 1 : I run the code as it as : http://ideone.com/MLGW4I

Case 2 : I add an additional printf statement, leaving the entire remaining code unchanged. : http://ideone.com/X9kngM

The change can be seen (addition of an extra printf statement) in line no. 31 of the code.

How can it be possible that a simple printf statement changes the output that follows, when nothing is changed anywhere else? Or is it some pretty big blunder that I'm making and am completely unaware of it?

Any help regarding this will be much appreciated.

• +6

By WarpSpeed, history, 4 years ago, ,

I have gone through sorting of simple 2-D arrays. And there are ample ways to do this efficiently. But lately, I'm facing some issues in sorting 2-D arrays with the following conditions:

Suppose there's a 2-D array with 2 rows and n columns. (Here n can vary from 1 upto 10^6) . All the entries are integer entries with the upper bound being 2 * 10^9 . The task here is to sort the elements in the first row in ascending order, preferably ( although, ascending/descending doesn't make much of a difference anyway ) and the elements of second row should occupy their new positions corresponding to their previous row-1 elements ( irrespective of their relations among other row-2 elements ).

A sample:

Suppose the array is as follows:

5 6 4 8 7 3

4 9 5 1 0 2

Then after sorting the final array should become:

3 4 5 6 7 8

2 5 4 9 0 1

With the conditions of n's upper bound going as high as 10^6, trivial methods of sorting this serve useless and lead to TLE message. How can the aforementioned task be achieved in the most efficient manner?