結果

問題 No.370 道路の掃除
ユーザー yun_app
提出日時 2016-05-17 10:14:19
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,172 bytes
コンパイル時間 2,304 ms
コンパイル使用メモリ 77,744 KB
実行使用メモリ 37,052 KB
最終ジャッジ日時 2024-10-06 05:10:32
合計ジャッジ時間 5,332 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 4
権限があれば一括ダウンロードができます

ソースコード

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()));
        }
        
        int ans = Integer.MAX_VALUE;
        for(int i=0;i<M-N+1;i++){
            int sum = 0;
            if((gomi.get(i) < 0 && gomi.get(i+N-1) > 0) 
            || (gomi.get(i) > 0 && gomi.get(i+N-1) < 0)){
                sum += 2*Math.min(Math.abs(gomi.get(i)),Math.abs(gomi.get(i+N-1)));
            }
            sum += Math.max(Math.abs(gomi.get(i)),Math.abs(gomi.get(i+N-1)));
            ans = Math.min(ans,sum);
        }
        System.out.println(ans);
    }
}
0