In test case 1 it is giving run error , why? all other cases are fine

#include
#include
#include
using namespace std;

int main()
{
int n;
cin>>n;
int k;
cin>>k;
priority_queue<int,vector> pq;
int pos[n+1];
int arr[n];
int x;
for(int i=0;i<n;i++)
{ cin>>x;
pq.push(x);
arr[i]=x;
pos[x]=i;
}

int i=0;
while(k!=0)
{
	if(pq.top()>arr[i])
	{
		k--;
		int e=pq.top();
		int temp=arr[i];
		arr[i]=e;
		int y=pos[e];
		arr[pos[e]]=temp;
		pos[pq.top()]=i;
		pos[temp]=y;
	
	}
		pq.pop();
	i++;
}
for(int i=0;i<n;i++)
{
	cout<<arr[i]<<" ";
}

}

please save your code at

and send the link generated

i have done some changes

thank you, it worked, but the freopen wasn’t working so i removed that.

yes you have to remove that
this is for taking input from a file