-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor array pair
More file actions
43 lines (35 loc) · 1.28 KB
/
for array pair
File metadata and controls
43 lines (35 loc) · 1.28 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
34
35
36
37
38
39
40
41
42
43
import java.io.*;
import java.util.*;
class Result {
public static long solve(List<Integer> arr) {
int n = arr.size();
long count = 0;
for (int i = 0; i < n; i++) {
int maxVal = arr.get(i);
for (int j = i + 1; j < n; j++) {
maxVal = Math.max(maxVal, arr.get(j));
if ((long) arr.get(i) * arr.get(j) <= maxVal) {
count++;
}
}
}
return count;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out));
int arrCount = Integer.parseInt(bufferedReader.readLine().trim());
List<Integer> arr = new ArrayList<>();
String[] inputs = bufferedReader.readLine().split(" ");
for (int i = 0; i < arrCount; i++) {
arr.add(Integer.parseInt(inputs[i]));
}
long result = Result.solve(arr);
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
}