-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
52 lines (49 loc) · 940 Bytes
/
B.cpp
File metadata and controls
52 lines (49 loc) · 940 Bytes
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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,x,c=0;
cin>>n;
vector <int> v(n+1,0);
for(int i=0;i<n;i++)
{
cin>>x;
v[x]++;
}
for(int i=1;i<v.size();i++)
{
if(v[i]==1)
continue;
else
{
int j=i+1;
x=v[i];
while(x>1 && j<v.size())
{
if(v[j]==0)
{
v[j]=1;
x--;
c+=j-i;
j++;
}
else
{
j++;
}
}
if(x>1)
{
while(x>1)
{
v.push_back(1);
c+=n+1-i;
n++;
x--;
}
}
}
}
cout<<c;
return 0;
}