Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Collections;
- import java.util.LinkedList;
- import java.util.Scanner;
- public class A_Minimun_Land_Price {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- try {
- Scanner r = new Scanner(new File("G.in"));
- int loop;loop=r.nextInt();
- for(int i=0;i<loop;i++){
- int ans=0;int n =1;
- LinkedList<Integer> list = new LinkedList<Integer>();
- while(true){
- int land;land=r.nextInt();
- if(land==0){break;}
- list.add(land);
- }
- Collections.sort(list);
- for(int j = list.size()-1 ;j>=0;j--)
- {
- ans+=(2*Math.pow(list.get(j),n));
- n++;
- }
- if(ans>5*(Math.pow(10.0, 6.0)))System.out.println("Too expensive");
- else System.out.println(ans);
- list.clear();
- }
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- /*
- Input
- 8
- 20
- 15
- 10
- 13
- 25
- 11
- 35
- 0
- 10
- 20
- 2
- 3
- 5
- 0
- 10
- 9
- 8
- 7
- 6
- 4
- 5
- 0
- 42
- 53
- 20
- 63
- 100
- 20
- 30
- 0
- 2
- 4
- 6
- 8
- 10
- 0
- 3
- 4
- 33
- 22
- 0
- 39
- 38
- 22
- 30
- 2
- 0
- 10
- 25
- 30
- 40
- 5
- 0
- Output
- Too expensive
- 716
- 85578
- Too expensive
- 1156
- 1324
- 525542
- 59380
- */
Add Comment
Please, Sign In to add comment