結果

問題 No.838 Noelちゃんと星々3
ユーザー htensaihtensai
提出日時 2020-02-14 18:41:42
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 810 bytes
コンパイル時間 2,815 ms
コンパイル使用メモリ 78,352 KB
実行使用メモリ 50,500 KB
最終ジャッジ日時 2024-04-16 01:09:23
合計ジャッジ時間 6,703 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 54 ms
37,216 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 51 ms
36,824 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 52 ms
37,032 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 50 ms
37,180 KB
testcase_21 AC 52 ms
37,136 KB
testcase_22 AC 51 ms
36,952 KB
testcase_23 AC 54 ms
37,268 KB
testcase_24 AC 53 ms
37,064 KB
testcase_25 AC 52 ms
37,184 KB
testcase_26 AC 53 ms
37,040 KB
testcase_27 AC 53 ms
37,172 KB
testcase_28 AC 54 ms
36,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	public static void main (String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] arr = new int[n + 2];
		String[] line = br.readLine().split(" ", n);
		for (int i = 1; i <= n; i++) {
		    arr[i] = Integer.parseInt(line[i - 1]);
		}
		arr[0] = Integer.MIN_VALUE / 2;
		arr[n + 1] = Integer.MAX_VALUE / 2;
		Arrays.sort(arr);
		long total = 0;
		for (int i = 1; i <= n; i++) {
		    if (arr[i] - arr[i - 1] < arr[i + 1] - arr[i]) {
		        total += arr[i] - arr[i - 1];
		        arr[i] = arr[i - 1];
		    } else {
		        total += arr[i + 1] - arr[i];
		        arr[i] = arr[i + 1];
		    }
		}
		System.out.println(total);
    }
    
}
0