Language: C++

import java.util.*;

class Main{
  private static long answer = Long.MAX_VALUE;
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int all = sc.nextInt();
    int choice = sc.nextInt();
    List<Integer> minus = new ArrayList<>();
    List<Integer> plus = new ArrayList<>();
    
    for(int i = 0;i<all;i++){
      int x = sc.nextInt();
      if(x < 0){
        minus.add(Integer.valueOf(Math.abs(x)));
      }else{
        plus.add(Integer.valueOf(x));
      }
    }
    Collections.sort(minus);
    
    check(plus,minus,choice);
    check(minus,plus,choice);
               
    System.out.println(answer);
  }
  
  public static void check(List<Integer> a,List<Integer> b,int c){
    for(int i = 0;i<a.size() && i<c;i++){
      if(c - i - 1 > 0){
        if(b.size() > c - i - 2){
          answer = Math.min(answer,2 * a.get(i) + b.get(c - i -2));
        }
      }
      else{
        answer = Math.min(answer,a.get(c - 1));
      }
    }
  }
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:10: error: expected ':' before 'static'
    4 |   private static long answer = Long.MAX_VALUE;
      |          ^~~~~~~
      |          :
a.cc:4:32: error: 'Long' was not declared in this scope; did you mean 'long'?
    4 |   private static long answer = Long.MAX_VALUE;
      |                                ^~~~
      |                                long
a.cc:4:23: error: ISO C++ forbids in-class initialization of non-const static member 'Main::answer'
    4 |   private static long answer = Long.MAX_VALUE;
      |                       ^~~~~~
a.cc:5:9: error: expected ':' before 'static'
    5 |   public static void main(String args[]){
      |         ^~~~~~~
      |         :
a.cc:5:27: error: 'String' has not been declared
    5 |   public static void main(String args[]){
      |                           ^~~~~~
a.cc:28:9: error: expected ':' before 'static'
   28 |   public static void check(List<Integer> a,List<Integer> b,int c){
      |         ^~~~~~~
      |         :
a.cc:28:28: error: 'List' has not been declared
   28 |   public static void check(List<Integer> a,List<Integer> b,int c){
      |                            ^~~~
a.cc:28:32: error: expected ',' or '...' before '<' token
   28 |   public static void check(List<Integer> a,List<Integer> b,int c){
      |                                ^
a.cc:40:2: error: expected ';' after class definition
   40 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:6:5: error: 'Scanner' was not declared in this scope
    6 |     Scanner sc = new Scanner(System.in);
      |     ^~~~~~~
a.cc:7:15: error: 'sc' was not declared in this scope
    7 |     int all = sc.nextInt();
      |               ^~
a.cc:9:5: error: 'List' was not declared in this scope
    9 |     List<Integer> minus = new ArrayList<>();
      |     ^~~~
a.cc:9:10: error: 'Integer' was not declared in this scope
    9 |     List<Integer> minus = new ArrayList<>();
      |          ^~~~~~~
a.cc:9:19: error: 'minus' was not declared in this scope
    9 |     List<Integer> minus = new ArrayList<>();
      |                   ^~~~~
a.cc:9:31: error: 'ArrayList' does not name a type
    9 |     List<Integer> minus = new ArrayList<>();
      |                               ^~~~~~~~~
a.cc:9:41: error: expected primary-expression before '>' token
    9 |     List<Integer> minus = new ArrayList<>();
      |                                         ^
a.cc:9:43: error: expected primary-expression before ')' token
    9 |     List<Integer> minus = new ArrayList<>();
      |                                           ^
a.cc:10:19: error: 'plus' was not declared in this scope
   10 |     List<Integer> plus = new ArrayList<>();
      |                   ^~~~
a.cc:10:30: error: 'ArrayList' does not name a type
   10 |     List<Integer> plus = new ArrayList<>();
      |                              ^~~~~~~~~
a.cc:10:40: error: expected primary-expression before '>' token
   10 |     List<Integer> plus = new ArrayList<>();
      |                                        ^
a.cc:10:42: error: expected primary-expression before ')' token
   10 |     List<Integer> plus = new ArrayList<>();
      |                                          ^
a.cc:15:35: error: 'Math' was not declared in this scope
   15 |         minus.add(Integer.valueOf(Math.abs(x)));
      |                                   ^~~~
a.cc:20:5: error: 'Collections' was not declared in this scope
   20 |     Collections.sort(minus);
      |     ^~~~~~~~~~~
a.cc:25:5: error: 'System' was not declared in this scope
   25 |     System.out.println(answer);
      |     ^~~~~~
a.cc: In static member function 'static void Main::check(int)':
a.cc:29:21: error: 'a' was not declared in this scope
   29 |     for(int i = 0;i<a.size() && i<c;i++){
      |                     ^
a.cc:29:35: error: 'c' was not declared in this scope
   29 |     for(int i = 0;i<a.size() && i<c;i++){
      |                                   ^
a.cc:31:12: error: 'b' was not declared in this scope
   31 |         if(b.size() > c - i - 2){
      |            ^
a.cc:32:20: error: 'Math' was not declared in this scope
   32 |           answer = Math.min(answer,2 * a.get(i) + b.get(c - i -2));
      |                    ^~~~
a.cc:36:18: error: 'Math' was not declared in this scope
   36 |         answer = Math.min(answer,a.get(c - 1));
      |                  ^~~~