You are not logged in. Please login at to post your questions!


How to resolve time limit exceed error from my program

include <iostream>
#include <algorithm>
using namespace std;

int main()
int n;
int s[n];
for(int k=0;k<n;k++)
for(int m=0;m<n;m++
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!!

asked 06 Dec '14, 10:01

chaman_amit's gravatar image

accept rate: 0%

edited 06 Dec '14, 14:37

betlista's gravatar image

3★betlista ♦♦

Post a link to your code instead of pasting the entire code here.

(06 Dec '14, 11:26) gautam943★

Okk dude!!

(06 Dec '14, 13:08) chaman_amit1★

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


answered 06 Dec '14, 11:25

gautam94's gravatar image

accept rate: 11%

edited 06 Dec '14, 11:29

Thanks finally get my code accepted!!

(06 Dec '14, 13:13) chaman_amit1★

Why i getting code accepted in this case and not in that case due to time limit exceeded although these are same Plz help me!!

(06 Dec '14, 13:49) chaman_amit1★

@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. :)

(06 Dec '14, 14:03) ansh1star0333★

I won't find any option to mark as correct answer , plz tell me so i ll do that!!

(06 Dec '14, 15:44) chaman_amit1★

Can anyone please explain me why it is giving TIME LIMIT EXCEEDED ?


answered 18 Feb '18, 21:58

samlmxh21's gravatar image

accept rate: 0%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 06 Dec '14, 10:01

question was seen: 11,244 times

last updated: 18 Feb '18, 21:58