-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPair_of_Roses.java
More file actions
33 lines (32 loc) · 1.08 KB
/
Pair_of_Roses.java
File metadata and controls
33 lines (32 loc) · 1.08 KB
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
import java.util.Arrays;
import java.util.Scanner;
public class Pair_of_Roses {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int test=s.nextInt();
for (int k = 0; k < test; k++) {
int n=s.nextInt();
int arr[]=new int[n];
for (int i = 0; i < n; i++) {
arr[i]=s.nextInt();
}
Arrays.sort(arr);
int am=s.nextInt();
int p1=0,p2=0;
int min=Integer.MAX_VALUE;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(arr[i]+arr[j]==am && i!=j) {
if(min>Math.abs(arr[i]-arr[j]))
{
min=Math.abs(arr[i]-arr[j]);
p1=arr[i];
p2=arr[j];
}
}
}
}
System.out.println("Deepak should buy roses whose prices are "+p1+" and "+p2+".");
}
}
}