Why I am getting wrong answer?

well,i was trying this question:https://www.hackerrank.com/contests/may13/challenges/equal
and i am getting wrong answer for two test cases can someone tell me where this program is going wrong along with valid solution to it:

``````#include<stdio.h>

#include<algorithm>
using namespace std;
int main()
{
int t,l1=0,i,n;
long k=0,s1=0,s=0;
int arr[10001];
int arr1[200];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
sort(arr,arr+n);
s1=0;
for(i=0;i<n-1;i++)
{

if(arr[i]!=arr[i+1])
{
s=arr[i+1]-arr[i];
s1+=s;
if(i!=n-2)
arr[i+2]+=s1;
if(s>=5)
{
k+=s/5;
s=s%5;
}
if(s>=0)
{
k+=s/2;
s=s%2;
}

k+=s;
}
}
printf("%ld\n",k);
//		arr1[l1++]=k;
k=0;
}
/*	for(i=0;i<l1;i++)
printf("%d\n",arr1[i]);*/
return 0;
}
``````

Check for this test case…
INPUT:

1

3

1 5 5

OUTPUT should be 3 i guess
you answer gives 4 as the output…

Hope you got the mistake…There is a slight mistake in code…Hope you got the mistake

Happy coding…

1 Like