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 bd08e24 commit 28ecc36Copy full SHA for 28ecc36
Solutions/[17]_3.cpp
@@ -0,0 +1,26 @@
1
+#include <bits/stdc++.h>
2
+
3
+using namespace std;
4
5
+int n;
6
+vector<int> data;
7
8
+int main(void) {
9
+ cin >> n;
10
+ for (int i = 0; i < n; i++) {
11
+ int x;
12
+ cin >> x;
13
+ data.push_back(x);
14
+ }
15
16
+ // 오름차순 정렬 수행
17
+ sort(data.begin(), data.end());
18
19
+ // 불만도의 합 계산
20
+ long long result = 0;
21
+ for (int i = 1; i <= n; i++) {
22
+ result += abs(i - data[i - 1]);
23
24
25
+ cout << result;
26
+}
0 commit comments