Time limit exceeded

#include <stdio.h>

int main(void) {
int t,i,n,j,k,num;
scanf("%d",&t);
int arr[t];
for(i=0;i<t;i++)
{
scanf("%d",&arr[i]);

}
for(i=0;i<t;i++)
{
    for(j=i+1;j<t;j++)
    {
        if(arr[i]>arr[j])
        {
            num=arr[i];
            arr[i]=arr[j];
            arr[j]=num;
            
        }
    }
}
for(i=0;i<t;i++)
{
    printf("%d\n",arr[i]);
}

return 0;

}

This is my code for turbo sort.It is giving me time limit exceeded error pls help

It seems you are new here, a few guidelines first:

  1. Always format your code before posting. Link
  2. Tips to get faster response to your problem. Link.

Coming to your problem, (I am assuming you know how to calculate time complexity of your code, if not, learn it first).

The two nested for-loops make your solution O(t2). as t can be upto 106, your solution can take upto 1012 calculations. Given that codechef allows roughly 108 calcluations per second, calculate how much time your solution will take to finish.

P.S. Allowed time limit for each problem is mentioned in the bottom (along with tags, author details and other meta data).

2 Likes