結果

問題 No.1686 Geschenkt
ユーザー ks2m
提出日時 2021-09-24 21:21:52
言語 Java
(openjdk 23)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 450 bytes
コンパイル時間 3,783 ms
コンパイル使用メモリ 74,088 KB
実行使用メモリ 41,688 KB
最終ジャッジ日時 2024-07-05 09:55:58
合計ジャッジ時間 3,556 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		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();
		}
		sc.close();

		Arrays.sort(a);
		int ans = a[0];
		for (int i = 1; i < n; i++) {
			if (a[i - 1] + 1 != a[i]) {
				ans += a[i];
			}
		}
		System.out.println(ans);
	}
}
0