We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 410fdfe commit 7792246Copy full SHA for 7792246
Solutions/[17]_3.java
@@ -0,0 +1,29 @@
1
+import java.util.ArrayList;
2
+import java.util.Collections;
3
+import java.util.Scanner;
4
+
5
+public class Main {
6
7
+ public static void main(String[] args) {
8
+ Scanner sc = new Scanner(System.in);
9
10
+ int n = sc.nextInt();
11
+ ArrayList<Integer> data = new ArrayList<Integer>();
12
13
+ for (int i = 0; i < n; i++) {
14
+ data.add(sc.nextInt());
15
+ }
16
17
+ // 오름차순 정렬 수행
18
+ Collections.sort(data);
19
20
+ // 불만도의 합 계산
21
+ long result = 0;
22
+ for (int i = 1; i <= n; i++) {
23
+ result += Math.abs(i - data.get(i - 1));
24
25
26
+ System.out.println(result);
27
28
29
+}
0 commit comments