546B codeforces - Soldiers and Badges


546B codeforces


Soldiers and Badges

Solutions in c++

#include <iostream>

using namespace std;

int all[100002]={0},vis[100002]={0};

int main()

{
    int n,sol=0;

    cin>>n;

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

        cin>>all[i];

        vis[all[i]]++;

    }

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

        if(vis[all[i]]>1){

            int k=all[i];

            while(vis[k]){

                k++;

                sol++;

             }


            vis[all[i]]--;

            vis[k]=1;


      }

    }

    cout<<sol<<"\n";

    return 0;

}

Share on Google Plus

About Mohamed Sobhi

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 التعليقات:

إرسال تعليق