Guest User

Untitled

a guest
Sep 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.Collections;
  4. import java.util.LinkedList;
  5. import java.util.Scanner;
  6.  
  7.  
  8. public class A_Minimun_Land_Price {
  9.  
  10.     /**
  11.      * @param args
  12.      */
  13.     public static void main(String[] args) {
  14.         // TODO Auto-generated method stub
  15.  
  16.        
  17.         try {
  18.             Scanner r = new Scanner(new File("G.in"));
  19.            
  20.             int loop;loop=r.nextInt();
  21.             for(int i=0;i<loop;i++){
  22.                 int ans=0;int n =1;
  23.                 LinkedList<Integer> list = new LinkedList<Integer>();
  24.                 while(true){
  25.                
  26.                     int land;land=r.nextInt();
  27.                
  28.                     if(land==0){break;}
  29.                     list.add(land);
  30.                     }
  31.                
  32.                 Collections.sort(list);
  33.                 for(int j = list.size()-1 ;j>=0;j--)
  34.                     {
  35.                         ans+=(2*Math.pow(list.get(j),n));
  36.                         n++;
  37.                        
  38.                     }
  39.                 if(ans>5*(Math.pow(10.0, 6.0)))System.out.println("Too expensive");
  40.                 else System.out.println(ans);
  41.                 list.clear();
  42.            
  43.             }
  44.            
  45.            
  46.            
  47.            
  48.            
  49.         } catch (FileNotFoundException e) {
  50.             // TODO Auto-generated catch block
  51.             e.printStackTrace();
  52.         }
  53.     }
  54.  
  55. }
  56. /*
  57. Input
  58. 8
  59. 20
  60. 15
  61. 10
  62. 13
  63. 25
  64. 11
  65. 35
  66. 0
  67. 10
  68. 20
  69. 2
  70. 3
  71. 5
  72. 0
  73. 10
  74. 9
  75. 8
  76. 7
  77. 6
  78. 4
  79. 5
  80. 0
  81. 42
  82. 53
  83. 20
  84. 63
  85. 100
  86. 20
  87. 30
  88. 0
  89. 2
  90. 4
  91. 6
  92. 8
  93. 10
  94. 0
  95. 3
  96. 4
  97. 33
  98. 22
  99. 0
  100. 39
  101. 38
  102. 22
  103. 30
  104. 2
  105. 0
  106. 10
  107. 25
  108. 30
  109. 40
  110. 5
  111. 0
  112. Output
  113. Too expensive
  114. 716
  115. 85578
  116. Too expensive
  117. 1156
  118. 1324
  119. 525542
  120. 59380
  121. */
Add Comment
Please, Sign In to add comment