Language: Java

import java.util.*;
 
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in); 

        long N = sc.nextLong();
        long K = sc.nextLong();
        long[] x = new int[N];
        for(int i = 0; i < N; i++){
            x[i] = sc.nextlong();
        }
        sc.close();

        long left = left_num(x);
        long right;
        long xl = 0;
        long xr = 0;
        long min = 2*(x[N-1] - x[0]);
            right = N - left;
            //i:左側の個数
            for(int i = 0; i <= Math.min(left, K); i++){
                int j = K-i; //右側に行く個数
                if(right < j)
                    continue;
                else{
                    if(i == 0){
                        min = Math.min(min, Math.abs(x[left+K-1]));
                    }
                    if(j == 0)
                        min = Math.min(min, Math.abs(x[left-K]));
                    if(i > 0 && j > 0){
                        xl = x[left-i];
                        xr = x[left+j-1];
                        long dis = Math.min((Math.abs(xl) + Math.abs(xl-xr)),
                                             (Math.abs(xr) + Math.abs(xl-xr)));
                        min = Math.min(min, dis);
                    }
                }
                System.out.println(i + " " + j + " " + min);
            }
        System.out.println(min);

    }
    static long left_num(long[] a){
        long index = 0;
        while(a[index] < 0){
            index++;
        }
        return index;
    }
}

Compiler output:
Main.java:9: error: incompatible types: possible lossy conversion from long to int
        long[] x = new int[N];
                           ^
Main.java:9: error: incompatible types: int[] cannot be converted to long[]
        long[] x = new int[N];
                   ^
Main.java:11: error: cannot find symbol
            x[i] = sc.nextlong();
                     ^
  symbol:   method nextlong()
  location: variable sc of type Scanner
Main.java:19: error: incompatible types: possible lossy conversion from long to int
        long min = 2*(x[N-1] - x[0]);
                         ^
Main.java:23: error: incompatible types: possible lossy conversion from long to int
                int j = K-i; //???????
                         ^
Main.java:28: error: incompatible types: possible lossy conversion from long to int
                        min = Math.min(min, Math.abs(x[left+K-1]));
                                                             ^
Main.java:31: error: incompatible types: possible lossy conversion from long to int
                        min = Math.min(min, Math.abs(x[left-K]));
                                                           ^
Main.java:33: error: incompatible types: possible lossy conversion from long to int
                        xl = x[left-i];
                                   ^
Main.java:34: error: incompatible types: possible lossy conversion from long to int
                        xr = x[left+j-1];
                                     ^
Main.java:47: error: incompatible types: possible lossy conversion from long to int
        while(a[index] < 0){
                ^
10 errors