Boj2012_등수메기기

Published: by Creative Commons Licence

  • Tags:

boj2012_등수메기기

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<long long> v;
int main() {
	long long n,num;
	long long ans=0;
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &num);
		v.push_back(num);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++) {
		if (v[i] - (i + 1)>0) ans += (v[i] - (i + 1));
		else ans += ((i + 1) - v[i]);
	}
	printf("%lld", ans);
}