結果

問題 No.370 道路の掃除
ユーザー yun_appyun_app
提出日時 2016-05-17 10:23:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,205 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 78,808 KB
実行使用メモリ 50,496 KB
最終ジャッジ日時 2024-04-22 17:43:18
合計ジャッジ時間 4,634 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
50,128 KB
testcase_01 AC 52 ms
50,320 KB
testcase_02 AC 49 ms
50,236 KB
testcase_03 AC 49 ms
49,892 KB
testcase_04 AC 50 ms
50,252 KB
testcase_05 AC 49 ms
50,412 KB
testcase_06 AC 49 ms
49,944 KB
testcase_07 AC 49 ms
50,260 KB
testcase_08 AC 51 ms
50,360 KB
testcase_09 AC 51 ms
50,272 KB
testcase_10 AC 51 ms
50,332 KB
testcase_11 AC 51 ms
50,140 KB
testcase_12 AC 52 ms
50,396 KB
testcase_13 AC 51 ms
50,328 KB
testcase_14 AC 52 ms
50,144 KB
testcase_15 AC 52 ms
50,496 KB
testcase_16 AC 52 ms
50,404 KB
testcase_17 AC 52 ms
50,376 KB
testcase_18 AC 51 ms
49,940 KB
testcase_19 AC 50 ms
49,836 KB
testcase_20 AC 54 ms
50,416 KB
testcase_21 AC 54 ms
50,012 KB
testcase_22 AC 53 ms
50,348 KB
testcase_23 AC 51 ms
50,140 KB
testcase_24 AC 50 ms
50,460 KB
testcase_25 AC 52 ms
50,064 KB
testcase_26 AC 53 ms
50,416 KB
testcase_27 AC 51 ms
50,184 KB
testcase_28 AC 53 ms
50,200 KB
testcase_29 AC 54 ms
50,092 KB
testcase_30 AC 57 ms
50,272 KB
testcase_31 AC 54 ms
49,952 KB
testcase_32 AC 53 ms
50,364 KB
testcase_33 AC 56 ms
50,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int N = Integer.parseInt(line[0]);
        int M = Integer.parseInt(line[1]);
        
        ArrayList<Integer> gomi = new ArrayList<Integer>();
        for(int i=0;i<M;i++){
            gomi.add(Integer.parseInt(br.readLine()));
        }
        Collections.sort(gomi);
        int ans = Integer.MAX_VALUE;
        for(int i=0;i<M-N+1;i++){
            int sum = 0;
            int start = gomi.get(i);
            int goal  = gomi.get(i+N-1);
            if((start < 0 && goal > 0) 
            || (start > 0 && goal < 0)){
                sum += 2*Math.min(Math.abs(start),Math.abs(goal));
            }
            sum += Math.max(Math.abs(start),Math.abs(goal));
            ans = Math.min(ans,sum);
        }
        System.out.println(ans);
    }
}
0