Run error in my programme

#include
using namespace std;
int main() {
int n;
cin>>n;
int arr[n];
int arr2[1000]={0};
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
for(int i=0;i<n;i++)
{
arr2[arr[i]]++;
}
for(int i=0;i<1000;i++)
{
if(arr2[i]>0)
{
for(int j=0;j<arr2[i];j++)
{
cout<<i<<endl;
}
}
}
return 0;
}

@jatingarg17 See the Constraints:
1<=N<=10^6 0<=Ai<=10^6
You have restricted the size of your array to 1000 due to which it is giving runtime error for large test cases. Increase it to 10^6 and then check.

#include
using namespace std;
int main() {
int n;
cin>>n;
int arr[n];
int arr2[1000000];
for(int i=0;i<n;i++)
{
cin>>arr[i];

}
int max=arr[0];
for(int i=0;i<n;i++)
{
	if(arr[i]>max)
	{
		int temp=arr[i];
		max=arr[i];
		arr[i]=temp;
	}
}
for(int i=0;i<n;i++)
{
	arr2[arr[i]]++;
}
for(int i=0;i<=max;i++)
{
	if(arr2[i]>0)
	{
		for(int j=0;j<arr2[i];j++)
		{
			cout<<i<<" ";
		}
	}
}
return 0;

}
now I am facing time limit exceeded

@jatingarg17 https://ide.codingblocks.com/s/141095
Refer this.