๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐“ก๐“ธ๐“ธ๐“ถ๐Ÿฃ: ๐’œ๐“๐‘”๐‘œ๐“‡๐’พ๐“‰๐’ฝ๐“‚/์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ ํ’€์ด

BOJ2012 : ๋“ฑ์ˆ˜๋งค๊ธฐ๊ธฐ (Silver 3)

#include <iostream>
#include <algorithm>

using namespace std;
int N;
int prerank[500001];

long long rankingSystem()
{
    long long angry = 0;
    for (int i = 1; i <= N; i++)
    {
        angry += abs(prerank[i] - i);
    }
    return angry;
}

int main()
{
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        cin >> prerank[i];
    }

    sort(prerank + 1, prerank + N + 1);
    cout << rankingSystem();
}