How to reduce time complexity?

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);

	int x = scn.nextInt();
	int n = scn.nextInt();

	ArrayList<Integer> salary = new ArrayList<>();
	ArrayList<String> name = new ArrayList<>();

	for (int i = 0; i < n; i++) {

		name.add(scn.next());
		salary.add(scn.nextInt());

// System.out.println(salary.get(i));
// System.out.println(name.get(i));
}

	for (int i = 0; i < n - 1; i++) {

		for (int j = 0; j < n-1-i; j++) {

			if (salary.get(j) < salary.get(j + 1)) {

				int temp = salary.get(j);
				salary.set(j, salary.get(j + 1));
				salary.set(j+1,temp);

// System.out.println(salary.get(j));
// System.out.println(salary.get(j+1));

				String temp1 = name.get(j);
				name.set(j, name.get(j + 1));
				name.set(j+1,temp1);
			}	
		}
	}
	
	int count;
	
	for(int i=0;i<n-1;i++) {
		
		count=0;
		for(int j=i;j<n-1 && salary.get(j) == salary.get(j + 1);j++) {
								
				count++;
				i++;
		}
		if(count>0) {
		for(int j=i-count;j<i;j++)
		{	int c=count;
			for(int k=i-count;(k<n-1) && (c!=0);k++) {
				c--;
				int w=name.get(k).compareTo(name.get(k+1));
				
				if(w>0) {
					String temp1 = name.get(k);
					name.set(k, name.get(k + 1));
					name.set(k+1,temp1);
				}
			}
		}
		
	}
}
	
	for (int i = 0; i < n; i++) {
		
		if(salary.get(i)>=x) {
		System.out.print(name.get(i)+" ");
		System.out.println(salary.get(i));
		}
	}
}

you can wrap name and salary in a class and sort the class using inbuilt sort function(nlogn)
make your own compareTo by implementing comparator class

how to use sort in user defined class .If i sort salaries then i have to change corresponding names

we make our class implement comparator interface…by implementing comparator interface we have to give body to compareTo function…in compareTo function we have to write the logic of sort function…

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.