SHARE
TWEET

codeforce - Soldier and Badges

jakaria_hossain May 14th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define fastread()(ios_base::sync_with_stdio(false),cin.tie(NULL));
  5. int main()
  6. {
  7.     int n;
  8.     scanf("%d",&n);
  9.     int ara[n+1];
  10.     for(int i=0;i<n;i++)scanf("%d",&ara[i]);
  11.     sort(ara,ara+n);
  12.     int c=0;
  13.     for(int i=1;i<n;i++)
  14.     {
  15.         if(ara[i]==ara[i-1])
  16.         {
  17.             c++;
  18.             ara[i]++;
  19.         }
  20.         else if(ara[i]<ara[i-1])
  21.         {
  22.             int a=ara[i-1]-ara[i];
  23.             ara[i]+=a+1;
  24.             c+=a+1;
  25.         }
  26.     }
  27.     printf("%d\n",c);
  28.     return 0;
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top