結果

問題 No.1686 Geschenkt
ユーザー みーすけ
提出日時 2021-10-03 14:03:27
言語 Java
(openjdk 23)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 472 bytes
コンパイル時間 2,637 ms
コンパイル使用メモリ 74,100 KB
実行使用メモリ 41,304 KB
最終ジャッジ日時 2024-07-21 08:03:47
合計ジャッジ時間 3,989 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

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