static double calc ( double [ ] p , double budget ) {
  double ans = 1.0 ;
  int n = p . length ;
  Arrays . sort ( p ) ;
  for ( int i = 0 ;
  i < n - 1 ;
  i ++ ) {
    double d = p [ i + 1 ] - p [ i ] ;
    double need = d * ( i + 1 ) ;
    if ( budget < need ) {
      double minP = p [ i ] + budget / ( i + 1 ) ;
      for ( int j = 0 ;
      j <= i ;
      j ++ ) {
        ans *= minP ;
      }
      for ( int j = i + 1 ;
      j < n ;
      j ++ ) {
        ans *= p [ j ] ;
      }
      return ans ;
    }
    budget -= need ;
  }
  double minP = p [ n - 1 ] + budget / n ;
  return Math . pow ( minP , n ) ;
}

static double calc ( double [ ] p , double budget ) { double ans = 1.0 ; int n = p . length ; Arrays . sort ( p ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { double d = p [ i + 1 ] - p [ i ] ; double need = d * ( i + 1 ) ; if ( budget < need ) { double minP = p [ i ] + budget / ( i + 1 ) ; for ( int j = 0 ; j <= i ; j ++ ) { ans *= minP ; } for ( int j = i + 1 ; j < n ; j ++ ) { ans *= p [ j ] ; } return ans ; } budget -= need ; } double minP = p [ n - 1 ] + budget / n ; return Math . pow ( minP , n ) ; }
(method_declaration (modifiers) type: (floating_point_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (floating_point_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (floating_point_type) name: (identifier))) body: (block (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (decimal_floating_point_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (array_access array: (identifier) index: (identifier))))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))))) (return_statement (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (identifier))))) (return_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))