1.
package
contestVolumes.volume118;
import
java.util.ArrayList;
import
java.util.Collections;
import
java.util.Scanner;
/**
* FWP,
Ausgewählte Probleme aus dem ACM Programming Contest, SS10
*
Problem: 11824 - A Minimum Land Price
* Link:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=226&problem=2924&mosmsg=Submission+received+with+ID+8228022
*
*
@author Siegfried Ippisch
*
@version 1.0
*
*
Method : -
*
Status : Accepted
*
Runtime: 0.132
*/
public class
AMinimumLandPrice {
public
static
int MAX = 5000000;
public
static
void main(String[] args){
Scanner
in = new Scanner(System.in);
int
n = in.nextInt();
cases:
while(n-- > 0){
ArrayList<Integer> list =
new ArrayList<Integer>(40);
int next = in.nextInt();
while(next != 0){
list.add(next);
next =
in.nextInt();
}
Collections.sort(list);
int pow = 1;
long price = 0;
for(int i=list.size()-1; i>=0;
i--){
long a =
pow(list.get(i),pow++);
price += a+a;
if(price >
MAX || price < 0){
System.out.println("Too expensive");
continue cases;
}
}
System.out.println(price);
}
in.close();
}
public
static
long pow(int b, int p){
long
a = 1;
for(int
i=0; i<p; i++){
a*=b;
if(a > MAX)
return MAX+1;
}
return
a;
}
}