UVA – 787 – Maximum Sub-sequence Product

import java.util.ArrayList;
import java.util.Scanner;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) {
		int v;
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			ArrayList<Integer> a = new ArrayList<Integer>();
			while (in.hasNext() && ((v = in.nextInt()) != -999999))	a.add(v);
			BigInteger max = BigInteger.valueOf(a.get(0));
			for (int i = 0; i < a.size(); i++) {
				BigInteger cur = BigInteger.valueOf(a.get(i));
				max = cur.max(max);
				for (int j = i + 1; j < a.size(); j++) {
					cur = cur.multiply(BigInteger.valueOf(a.get(j)));
					max = cur.max(max);
				}
			}
			System.out.println(max);
		}
	}

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: