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!!
As you know, this problem asks you to find the smallest non-negative integer N that can be made by repeatedly subtracting K.
There’s at least two possible reason why you’re getting TLE error, and both have to do with the problem constraints.
1 \leq T \leq 10^5 1 \leq N \leq 10^9 0 \leq K \leq 10^9
For N=1 and K=0, does your program ever terminate?
And for T=10^5 test cases in which each N=10^9 and each K=1, your program requires 10^5 \cdot 10^9 subtractions. No matter how fast your program is, 10^{14} operations is likely to run out of time.