Lec 02 - Sorting
Last updated
Last updated
public class nothanks {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
ArrayList<Integer> card = new ArrayList<>();
for (int i = 0; i < n; i += 1) {
card.add(sc.nextInt());
}
Collections.sort(card);
int ans = card.get(0);
for (int i = 1; i < n; i += 1) {
if (card.get(i - 1) + 1 != card.get(i)) {
ans += card.get(i);
}
}
System.out.println(ans);
}
}