-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpriyanka-and-toys.c
More file actions
65 lines (60 loc) · 766 Bytes
/
priyanka-and-toys.c
File metadata and controls
65 lines (60 loc) · 766 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
53
54
55
56
57
58
59
60
61
62
63
64
65
//priyanka-and-toys
//mandeep singh
#include<stdio.h>
#include<stdlib.h>
void insertion(int a[], int s)
{
int i, j;
int current;
for(i = 1; i< s; i++)
{
current = a[i];
for(j = i-1; j>=0; j--)
{
if(current < a[j])
a[j+1] = a[j];
else
break;
}
a[j+1] = current;
}
}
int main()
{
int i,j,k,w,flag=0,n,unit,x;
int arr[100000];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
//sort the array;
insertion(arr,n);
//arr sorted now
i=0;
unit=0;
while(i<n)
{
flag=0;
w=arr[i];
unit++;
x=i;
for(j=x+1;j<=n;j++)
{
flag=0;
if(arr[j]<=(w+4) && arr[j]>=w)
{
i++;
flag=1;
}
if(flag==0)
break;
}
if(flag==0)
{
i++;
}
}
printf("%d",unit);
return 0;
}