結果

問題 No.838 Noelちゃんと星々3
ユーザー htensaihtensai
提出日時 2020-02-14 18:41:42
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 810 bytes
コンパイル時間 3,762 ms
コンパイル使用メモリ 73,864 KB
実行使用メモリ 61,492 KB
最終ジャッジ日時 2023-07-28 16:57:11
合計ジャッジ時間 8,484 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 46 ms
49,340 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 46 ms
49,556 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 45 ms
49,676 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 46 ms
49,188 KB
testcase_21 AC 46 ms
49,680 KB
testcase_22 AC 46 ms
51,240 KB
testcase_23 AC 46 ms
49,796 KB
testcase_24 AC 45 ms
49,336 KB
testcase_25 AC 45 ms
49,276 KB
testcase_26 AC 45 ms
49,136 KB
testcase_27 AC 46 ms
49,232 KB
testcase_28 AC 45 ms
49,344 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