Competitive/Collaborative Programming Class

ICPC Computer Programming Contest Prep

Problem Solving in Computer Science

Fall 2011 -- CSC 2700 Section 02

[Isaac's Home Page ]  [Mailing List ]  [Class Page ]  [Normal ]  

8/b/Main11824.java

import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.math.BigInteger;
public class Main11824 {
 	
	public static void main(String[] args) {
     	Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        BigInteger total = new BigInteger("5000000");
		BigInteger two = new BigInteger("2");
		for(int i=0;i<n;i++) {
            int counter = 1;
			BigInteger sum = new BigInteger("0");
			int x = in.nextInt();
            ArrayList<Integer> a = new ArrayList<Integer>();
			while(x != 0) {
				a.add(x);
				x = in.nextInt();
			}
            Object[] a2 = a.toArray();
			Arrays.sort(a2);
			for(int j=a2.length-1;j>=0;j--) {
				String y = a2[j].toString();
				BigInteger p = new BigInteger(y);
				p = p.pow(counter);
				sum = sum.add(p);
				counter++;
			}
			sum = sum.multiply(two);
			BigInteger compare = total.subtract(sum);
			if(compare.compareTo(new BigInteger("0")) == -1) {
                System.out.println("Too expensive");
			} else
				System.out.println(sum);
		}	
	}

}

The statements and opinions included in these pages are those of only. Any statements and opinions included in these pages are not those of Louisiana State University or the LSU Board of Supervisors.
© 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Isaac Traxler