結果

問題 No.1686 Geschenkt
ユーザー みーすけみーすけ
提出日時 2021-10-03 14:03:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 472 bytes
コンパイル時間 2,774 ms
コンパイル使用メモリ 72,928 KB
実行使用メモリ 56,148 KB
最終ジャッジ日時 2023-09-28 13:24:54
合計ジャッジ時間 5,086 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,624 KB
testcase_01 AC 127 ms
55,840 KB
testcase_02 AC 131 ms
56,008 KB
testcase_03 AC 129 ms
55,992 KB
testcase_04 AC 126 ms
55,776 KB
testcase_05 AC 130 ms
55,908 KB
testcase_06 AC 128 ms
56,068 KB
testcase_07 AC 127 ms
55,864 KB
testcase_08 AC 127 ms
55,788 KB
testcase_09 AC 129 ms
56,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int sum = a[0];
        for (int i = n - 1; i > 0; i--) {
            if (a[i - 1] != a[i] - 1)
                sum += a[i];
        }
        System.out.println(sum);
    }
}
0