結果

問題 No.370 道路の掃除
ユーザー tentententen
提出日時 2022-07-30 16:33:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,361 bytes
コンパイル時間 3,344 ms
コンパイル使用メモリ 76,816 KB
実行使用メモリ 50,524 KB
最終ジャッジ日時 2023-09-27 18:53:12
合計ジャッジ時間 6,743 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,436 KB
testcase_01 AC 44 ms
49,116 KB
testcase_02 AC 45 ms
49,316 KB
testcase_03 AC 45 ms
49,192 KB
testcase_04 AC 44 ms
49,184 KB
testcase_05 AC 45 ms
49,284 KB
testcase_06 AC 45 ms
49,292 KB
testcase_07 AC 44 ms
49,112 KB
testcase_08 AC 44 ms
49,196 KB
testcase_09 AC 45 ms
49,364 KB
testcase_10 AC 46 ms
49,476 KB
testcase_11 AC 46 ms
49,168 KB
testcase_12 AC 47 ms
49,324 KB
testcase_13 AC 45 ms
49,592 KB
testcase_14 AC 45 ms
47,852 KB
testcase_15 AC 47 ms
49,424 KB
testcase_16 AC 46 ms
49,272 KB
testcase_17 AC 45 ms
49,172 KB
testcase_18 AC 46 ms
49,400 KB
testcase_19 AC 46 ms
49,416 KB
testcase_20 AC 58 ms
50,228 KB
testcase_21 AC 58 ms
50,116 KB
testcase_22 AC 52 ms
49,956 KB
testcase_23 AC 54 ms
49,960 KB
testcase_24 AC 47 ms
49,280 KB
testcase_25 AC 52 ms
50,296 KB
testcase_26 AC 57 ms
50,524 KB
testcase_27 AC 48 ms
49,424 KB
testcase_28 AC 50 ms
49,192 KB
testcase_29 AC 54 ms
50,252 KB
testcase_30 AC 59 ms
48,552 KB
testcase_31 AC 53 ms
50,168 KB
testcase_32 AC 54 ms
50,192 KB
testcase_33 AC 58 ms
50,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[] positions = new int[n];
        for (int i = 0; i < n; i++) {
            positions[i] = sc.nextInt();
        }
        Arrays.sort(positions);
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i + m - 1 < n; i++) {
            int tmp = positions[i + m - 1] - positions[i] + Math.min(Math.abs(positions[i]),Math.abs(positions[i + m - 1]));
            ans = Math.min(ans, tmp);
        }
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0