Pabon_SEC

Maximum Sub-sequence Product

Feb 17th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.13 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         BigInteger mul, mx;
  9.  
  10.         long a, b;
  11.  
  12.         int i, j, k;
  13.  
  14.         long[] arr = new long[103];
  15.  
  16.         Scanner sc = new Scanner(System.in);
  17.  
  18.         while (sc.hasNext()) {
  19.  
  20.             a = sc.nextLong();
  21.  
  22.             if (a == -999999) {
  23.                 break;
  24.             }
  25.  
  26.             arr[1] = a;
  27.  
  28.             a = sc.nextLong();
  29.  
  30.             for (k = 1;;) {
  31.  
  32.                 if (a == -999999) {
  33.                     break;
  34.                 }
  35.  
  36.                 arr[++k] = a;
  37.  
  38.                 a = sc.nextLong();
  39.             }
  40.  
  41.             b = -9999999;
  42.  
  43.             mx = BigInteger.valueOf(b);
  44.  
  45.             for (i = 1; i <= k; i++) {
  46.  
  47.                 mul = BigInteger.valueOf(arr[i]);
  48.                 mx = mul.max(mx);
  49.  
  50.                 for (j = i + 1; j <= k; j++) {
  51.  
  52.                     mul = mul.multiply(BigInteger.valueOf(arr[j]));
  53.                     mx = mul.max(mx);
  54.                 }
  55.             }
  56.  
  57.             System.out.println("" + mx);
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment