-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_16678.java
More file actions
40 lines (30 loc) · 794 Bytes
/
BOJ_16678.java
File metadata and controls
40 lines (30 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package ps;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
public class BOJ_16678 {
public static void main(String[] args) throws Exception{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(in.readLine());
Long[] arr = new Long[N];
for(int i=0;i<N;i++) {
arr[i] = Long.parseLong(in.readLine());
}
Arrays.sort(arr);
long now = 1;
long sum = 0;
for(int i=0;i<arr.length;i++) {
if(now > arr[i].longValue())continue;
if(now == arr[i].longValue()) {
now++;
continue;
}
sum += (arr[i] - now);
now++;
}
System.out.println(sum);
}
}