forked from amankayat/HackerRank-Solution-Algorithm-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoldier_and_badges.cpp
65 lines (56 loc) · 1.05 KB
/
Soldier_and_badges.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
using namespace std;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a)
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define bp(i) __builtin_popcount(i)
ll mod=1e9+7;
int main()
{
int n;cin>>n;
int arr[n];
int dp[3005]={0};
f(i,0,n)
{cin>>arr[i];
dp[arr[i]]++;}
int i=0,j=1,f=0;
int k=*max_element(arr,arr+n);
ll c=0;
for(int i=1;i<=k;i++)
{
while(dp[i]>1)
{ if(j<i)
j=i+1;
if(j>=3003)
{
j++;
}
else{
while(dp[j]!=0)
{
j++;
}
dp[j]++;
}
dp[i]--;
c+=(j-i);
}
}
cout<<c<<endl;
}