|  | 
|  | 
| вернуться в форум | Is it possible to solve this problem without sorting? I'm sure that my algorythm is correct. It's complexity is O(n log n), because I use quicksort, and then 2 linear
 procedures. Why do I get TimeLimitExceed? Is it possible
 not to use sorting?
Re: Is it possible to solve this problem without sorting? > I'm sure that my algorythm is correct. It's complexity isO
 > (n log n), because I use quicksort, and then 2 linear
 > procedures. Why do I get TimeLimitExceed? Is it possible
 > not to use sorting?
 
 because complexity of quicksort in worst case is O(n^2)
 use heapsort or mergesort and ur program 'll get accepted (
 or at least not TimeLimitExceeded ) ;)
Thank you very much! I used Merge Sort and I've just got and accepted. I appreciate your help a lot :)Who said that qsort is an O(n^2) algorithm?I got accepted in 0.06sec using qsort. >Re: Is it possible to solve this problem without sorting? Just use Random-Quick-Sort it'll take a little time to run it.Re: Is it possible to solve this problem without sorting? you can use the quick sort in short algorithimRe: Is it possible to solve this problem without sorting? Still AC with O(N^2). ::)But sorting i use.
Re: Is it possible to solve this problem without sorting? do as this#include <algorithm>
 using namespace std;
 
 int a[n];
 sort(a,a+n);
 | 
 | 
|