public static void main ( String [ ] args ) throws IOException {
  int n = readInt ( ) , k = readInt ( ) , arr [ ] = new int [ n ] ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    arr [ i ] = readInt ( ) ;
  }
  Arrays . sort ( arr ) ;
  int boxes = ( n - k ) * 2 ;
  ArrayList < Integer > s = new ArrayList ( ) ;
  int ans = arr [ n - 1 ] ;
  for ( int i = 0 ;
  i < boxes ;
  i ++ ) {
    s . add ( arr [ i ] ) ;
  }
  int left = 0 , right = s . size ( ) - 1 ;
  while ( left < right ) {
    ans = Math . max ( ans , s . get ( left ) + s . get ( right ) ) ;
    left ++ ;
    right -- ;
  }
  println ( ans ) ;
}

public static void main ( String [ ] args ) throws IOException { int n = readInt ( ) , k = readInt ( ) , arr [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = readInt ( ) ; } Arrays . sort ( arr ) ; int boxes = ( n - k ) * 2 ; ArrayList < Integer > s = new ArrayList ( ) ; int ans = arr [ n - 1 ] ; for ( int i = 0 ; i < boxes ; i ++ ) { s . add ( arr [ i ] ) ; } int left = 0 , right = s . size ( ) - 1 ; while ( left < right ) { ans = Math . max ( ans , s . get ( left ) + s . get ( right ) ) ; left ++ ; right -- ; } println ( ans ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (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: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation name: (identifier) arguments: (argument_list)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal)))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (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 (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier))))))