Issue in running the code

import java.util.*;
class pair implements Comparable{
int v;
int i;
public pair(int v,int i){
this.v=v;
this.i=i;
}
public int compareTo(pair o){
return o.v-this.v;
}
}
public class Main {

public static void main(String args[]) {
	Scanner s=new Scanner(System.in);
	int n=s.nextInt();
	int k=s.nextInt();
	int arr[]=new int[n];
	PriorityQueue<pair> pq=new PriorityQueue<>();
	for(int i=0;i<n;i++){
		arr[i]=s.nextInt();
		pair p=new pair(arr[i],i);
		pq.add(p);
	}
	int j=0;
	while(k>0&&j<n){
		pair p=pq.peek();
		pq.remove(p);
		if(p.v>arr[j]){
			//swap
			int temp=p.v;
			arr[p.i]=arr[j];
			arr[j]=temp;
			//update priorityqueue
			pair p2=new pair(arr[p.i],p.i);
			pq.remove(new pair(arr[p.i],j));
			pq.add(p2);
			k--;
		}
		j++;
	}
	for(int i=0;i<n;i++){
		System.out.print(arr[i]);
	}

}

}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.