結果

問題 No.370 道路の掃除
ユーザー tenten
提出日時 2020-10-15 08:42:26
言語 Java
(openjdk 23)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 75,516 KB
実行使用メモリ 42,464 KB
最終ジャッジ日時 2024-07-20 19:39:58
合計ジャッジ時間 7,532 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	int[] points = new int[m];
    	for (int i = 0; i < m; i++) {
    	    points[i] = sc.nextInt();
    	}
    	Arrays.sort(points);
    	int min = Integer.MAX_VALUE;
    	for (int i = 0; i + n <= m; i++) {
    	    int end = i + n - 1;
    	    if (points[i] * points[end] < 0) {
    	        min = Math.min(min, points[end] - points[i] + Math.min(-points[i], points[end]));
    	    } else {
    	        if (points[i] < 0) {
    	            min = Math.min(min, -points[i]);
    	        } else {
    	            min = Math.min(min, points[end]);
    	        }
    	    }
    	}
    	System.out.println(min);
	}
}
0