← Back to List

2012번: 등수 매기기 ↗

Solutions

C++14
283 B | 283 chars
#include <iostream>
#include <algorithm>
using namespace std;
long long N,S;
long long ar[550000];
long long f(long long  x)
{
	return x>0?x:-x;
}
int main()
{
	cin>>N;
	for(int x=0; x<N; x++) cin>>ar[x];
	sort(ar,ar+N);
	for(int x=0; x<N; x++)
	{
		S+=f(ar[x]-(x+1));
	}
	cout<<S;
}