-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMPS.java
54 lines (43 loc) · 1.33 KB
/
MPS.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
import java.*;
import java.math.BigInteger;
import java.io.*;
import java.util.*;
class Main {
private static BigInteger max [] = new BigInteger[110];
private static BigInteger min [] = new BigInteger[110];
private static BigInteger A [] = new BigInteger[110];
private static int N;
private static BigInteger mps() {
BigInteger ans = A[0];
max[0] = min[0] = ans;
BigInteger zero = new BigInteger("0");
for (int i = 1; i < N; ++i) {
if (A[i].compareTo(zero) == 1) {
BigInteger aMult = A[i].multiply(max[i - 1]);
BigInteger bMult = A[i].multiply(min[i - 1]);
max[i] = A[i].max(aMult);
min[i] = A[i].min(bMult);
} else {
BigInteger aMult = A[i].multiply(min[i - 1]);
BigInteger bMult = A[i].multiply(max[i - 1]);
max[i] = A[i].max(aMult);
min[i] = A[i].min(bMult);
}
ans = ans.max(max[i]);
}
return ans;
}
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
String line;
while ((line = br.readLine()) != null ) {
StringTokenizer st = new StringTokenizer(line);
int i = 0;
while (st.hasMoreTokens()) {
A[i++] = new BigInteger(st.nextToken());
}
N = i - 1;
System.out.println(mps());
}
}
}