-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex1.java
More file actions
38 lines (30 loc) · 1.14 KB
/
ex1.java
File metadata and controls
38 lines (30 loc) · 1.14 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
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class ex1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
BigInteger[] links = new BigInteger[N];
for (int i = 0; i < N; i++) {
links[i] = scanner.nextBigInteger();
}
Arrays.sort(links, Collections.reverseOrder());
BigInteger totalProduct = BigInteger.ONE;
for (BigInteger num : links) {
totalProduct = totalProduct.multiply(num);
}
BigInteger subsetProduct = BigInteger.ONE;
BigInteger remainingProduct = new BigInteger(totalProduct.toString());
int answ = 0;
for (int i = 0; i < N; i++) {
subsetProduct = subsetProduct.multiply(links[i]);
remainingProduct = remainingProduct.divide(links[i]);
if (subsetProduct.compareTo(remainingProduct) >= 0) {
answ = i + 1; // i + 1 because it's the count of elements
break;
}
}
System.out.println(answ);
}
}