http://www.codechef.com/problems/TSORT/
include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin>>n;
int s[n];
for(int k=0;k<n;k++)
cin>>s[k];
sort(s,s+n);
for(int m=0;m<n;m++
cout<<s[m]<<endl;
return 0;
}
I can’t understand why it is giving time limit exceed and which sorting algorithm does sort(s,s+n) uses and what’s is complexity ?? plz also suggest me some other algo to reduce complexity of my program!!
It’s getting TLE due to slower I/O. Using scanf
and printf
this solution will get AC. Accepted code
This problem can also be solved using counting sort in O(n) time.
C++ implementation
scanf printf faster than cin cout
STL Sort algorithm
2 Likes
Post a link to your code instead of pasting the entire code here.
Thanks finally get my code accepted!!
Why i getting code accepted in this case
http://www.codechef.com/viewsolution/5503082
and not in that case due to time limit exceeded although these are same
http://www.codechef.com/viewsolution/5503067
Plz help me!!
@chaman_amit If you got the answer for your question,then you should mark it as the correct answer,so that it won’t appear in unanswered questions.
2 Likes
I won’t find any option to mark as correct answer , plz tell me so i ll do that!!
https://www.codechef.com/viewsolution/17473205
Can anyone please explain me why it is giving TIME LIMIT EXCEEDED ?