-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFairPair.java
More file actions
29 lines (29 loc) · 894 Bytes
/
FairPair.java
File metadata and controls
29 lines (29 loc) · 894 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
import java.util.*;
public class FairPair {
private static int fairPair(int[] nums , int lower , int upper){
int count = 0;
for (int i = 0; i < nums.length; i++) {
for (int j = i+1; j < nums.length; j++) {
System.out.println(i+" "+j);
int sum = nums[i]+nums[j];
if (sum >= lower && sum <= upper) {
count++;
}
}
}
return count;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
int lower = sc.nextInt();
int upper = sc.nextInt();
int ans = fairPair(arr,lower,upper);
System.out.println(ans);
sc.close();
}
}