285C CodeForces - Building Permutation




++Solution in c


# include <bits/stdc++.h>

using namespace std;

int main() {

    long long int n;cin>>n;

    long long int a[n];long long int t=0;
   
    long long int f=1;

    for(long long int i=0;i<n;i++)

    {cin>>a[i];}

    sort(a,a+n);

    for(long long int i=0;i<n;i++)

    {

     t=t+abs(a[i]-f);   

      f++;  

    }

    cout<<t<<endl;

}

Share on Google Plus

About Unknown

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق