Skip to content

Commit 28ecc36

Browse files
authored
Create [17]_3.cpp
1 parent bd08e24 commit 28ecc36

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Solutions/[17]_3.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)