Sort Game Question in java

the output I am getting:
TESTCASE # 1 : wrong-answer (Time: 0.12 s)
TESTCASE # 2 : wrong-answer (Time: 0.85 s)
TESTCASE # 3 : wrong-answer (Time: 0.59 s)
TESTCASE # 4 : wrong-answer (Time: 2.12 s)
can you tell me the mistake i am making

import java.util.*;
public class Main {
public static void main(String args[]) {

	Scanner scan = new Scanner(System.in);
	//The base salary
	int x = scan.nextInt();
	// no. of enteries
	int n = scan.nextInt();
	String[] names=new String[n];
	int[] sal = new int[n];
	
	for(int i =0;i<n;i++){
		String s= scan.next();
		int money = scan.nextInt();
		names[i] = s;
		sal[i] = money;
	}
	
	
	for(int counter =0;counter<n;counter++){
		int max = counter;
		int j = counter+1;
		int flag = -1;
		for(;j<n;j++){
			
			if(sal[j]>sal[max]){
				max=j;
				flag = 0;
			}
			
		}
		int item = sal[counter];
		sal[counter] = sal[max];
		sal[max] = item;
		String name = names[counter];
		names[counter] = names[max];
		names[max] = name;
		
	}
	for(int i=0; i<n-1;i++){
		if(sal[i]==sal[i+1])
		{
			if(names[i].compareTo(names[i+1])>0){
				String item = names[i];
				names[i]=names[i+1];
				names[i+1] = item;
				
			}
		}
	}
			
	
	for(int i =0;i<n;i++){
		if(sal[i]>=x){
			String s = names[i];
			int money = sal[i];
			System.out.println(s+"  " + money);
		}
	}
	

}

}

Hi Vaibhav,
Your logic is wrong as you have to sort both name and salary at same time considering them as 1 data type which can store both string and integer. So in this problem you have to make one class employee which has two members name and salary. Then create an array of objects of that class and sort the array in decreasing order on the basis of salary and if the salary of two employes are same then sort in ascending order on basis of name of these two employes. Finally print those objects in array having salary greater than input salary.

Actually the oops concept is not introduced in the course yet so i think so there is a method to solve it without the array of objects. As we are sorting the name as pert the marks so all the names remain attached to the marks assigned to them and for the names with same marks we do not have to make changes in the location of the marks as they are same we simply swap the names.