Skip to content

Commit a7bb73b

Browse files
authored
[20250203] BOJ / 골드5 / 모독 / 권혁준
1 parent d02503f commit a7bb73b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class Main {
7+
8+
// IO field
9+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
static StringTokenizer st;
12+
13+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
14+
static int nextInt() {return Integer.parseInt(st.nextToken());}
15+
static long nextLong() {return Long.parseLong(st.nextToken());}
16+
static void bwEnd() throws Exception {bw.flush();bw.close();}
17+
18+
// Additional field
19+
20+
21+
public static void main(String[] args) throws Exception {
22+
23+
nextLine();
24+
int N = nextInt();
25+
int[] A = new int[N];
26+
for(int i=0;i<N;i++) A[i] = Integer.parseInt(br.readLine());
27+
Arrays.sort(A);
28+
29+
long ans = 0;
30+
int c = 1;
31+
for(int i=0;i<N;i++) {
32+
int p = i;
33+
while(i<N-1 && A[i] == A[i+1] && A[i] == c) i++;
34+
ans += (long)(i-p+1)*Math.max(0,A[p]-c++);
35+
}
36+
bw.write(ans+"\n");
37+
38+
39+
bwEnd();
40+
}
41+
42+
}
43+
44+
```

0 commit comments

Comments
 (0)