For this problem the solution is acceptable when an Integer[] array is used but not when the same algorithm is used with an int[] array. Why? Problem URL:http://www.codeforces.com/problemset/problem/682/B TLE Solution:http://www.codeforces.com/contest/682/submission/19309219 Accepted Solution: http://www.codeforces.com/contest/682/submission/19309197









Because Arrays.sort() with int[] is using QuickSort that is O(N^2) at worst case.
Arrays.sort() with Integer[] is using MergeSort that is O(N*log(N)) at worst case.
Thank you for the clarification. I will remember this.
This bug should actually be fixed in some version of Java, afaik. You can also apply random shuffle to the array before sorting and it should help with anti-quicksort tests.