File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments