TLE in TSORT

#include
using namespace std;
int main(void) {
int N;
cin>>N;
int arr[N];
for(int i=0;i<N;i++)
{
cin>>arr[i];
}
for(int k=0;k<N-1;k++)
{
for(int j=0;j<N-1-k;j++)
{
if(arr[j]>arr[j+1])
{
int t;
t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
}
for(int i=0;i<N;i++)
{
cout<<arr[i]<<" ";
}
return 0;
}

it is showing time limited exceeded help me where tio make changes im new to cp pls help

link of problem TSORT Problem - CodeChef

For Sorting, its best to use nlogn algorithm than n^2. In this problem, you are using n^2 which results TLE because n <= 10^6. You can just use the command sort( arr, arr + t ) to sort it in cpp.

1 Like

ok.thanks, need to focus on time complexity also