-
Notifications
You must be signed in to change notification settings - Fork 111
/
solution.java
56 lines (50 loc) · 1.59 KB
/
solution.java
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
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.*;
import java.util.Collections;
public class solution
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int test=sc.nextInt(); // number of test cases
while(test!=0)
{
int n=sc.nextInt(); // length of arrays
int k=sc.nextInt(); // value of k
Integer[] a1=new Integer[n];
Integer[] a2=new Integer[n];
// 1st ARRAY
for(int i=0;i<n;++i)
{
a1[i]=sc.nextInt();
}
// 2nd ARRAY
for(int i=0;i<n;++i)
{
a2[i]=sc.nextInt();
}
Arrays.sort(a1); //sorting the 1st array in reverse order
Arrays.sort(a2, Collections.reverseOrder()); //sorting the 2nd array in reverse order
int flag=0;
// if two indexes summ in both array is greater than k we will print NO else for any condition we will prent YES
for(int i=0;i<n;++i)
{
//checking if two indexes sum has the value greater than k or not
if(a1[i]+a2[i]<k)
{
flag=1;
break;
}
}
// if flag did not change we will print YES
if(flag==0)
{
System.out.println("YES");
}
else if(flag==1) // if flag is 1 means two indexes has sum greater than k
{
System.out.println("NO");
}
test--;
}
}
}