-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.java
More file actions
44 lines (42 loc) · 900 Bytes
/
Copy pathD.java
File metadata and controls
44 lines (42 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.*;
import java.io.*;
public class cf{
static boolean isSorted(int a[]){
for(int i=0;i<a.length-1;i++){
if(a[i]>a[i+1])
return false;
}
return true;
}
static void solve(int n,int x,int a[]){
int ans=0;
int i=0;
int temp=0;
while(i<n){
if(isSorted(a)==true){
System.out.println(ans);
return;
}
if(a[i]>x){
temp=x;
x=a[i];
a[i]=temp;
ans++;
}
i++;
}
System.out.println("-1");
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int x=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
solve(n,x,a);
}
}
}