Bob was conducting a marathon for
World Exercise day. The marathon was n kilo meters long. Bob wanted to place
refreshments at P points within the race. The supply was given at mile marker
0. Each of the P places had a van each. Each van would travel only till the
next refreshment point. Find out of all the vans which van travelled the most.
Input
The first line contains an integer
T. The number of test cases.
For each test case the first line contains two integers N, P. N - the total distance of the marathons and P - the number of refreshment spots.
In the next line P integers are given, the locations of all the refreshment spots.
For each test case the first line contains two integers N, P. N - the total distance of the marathons and P - the number of refreshment spots.
In the next line P integers are given, the locations of all the refreshment spots.
Output
The most distance travelled by any
van. Print the answer for each test case in a separate line.
Constraints:
1<=T<=100
2<=N<=1000
1<=P<=200
0 <Pi< N, where Pi is the mile marker of each
refreshment spots.
It is guaranteed that each mile marker will contain only one refreshment spot.
It is guaranteed that each mile marker will contain only one refreshment spot.
Sample Input
2
7 3
6 2 4
11 2
6 2
Sample Output
2
5
Explanation:
In the first test case the first 3
vans travel for a distance 2 kms (0-2, 2-4,4-6) and the last one a distance of
1 km (6-7).
In the second test case the the vans travel 2, 4 and 5 kms respectively. (0-2, 2-6,6-11)
Program:In the second test case the the vans travel 2, 4 and 5 kms respectively. (0-2, 2-6,6-11)
#include<stdio.h>
void sort(int *,int); /* function prototype */
int main()
{
int n,p,temp,diff=0,i,j,k,test_cases;
printf("input the number of test cases");
scanf("%d",&test_cases);
if((test_cases<1)||(test_cases>100))
printf("Invalid range");
else
{
for(k=1;k<=test_cases;k++)
{
printf("input the marathon long in km");
scanf("%d",&n);
if((n<2)||(n>1000))
printf("please give the valid length");
else{
printf("enter number of refreshment points");
scanf("%d",&p);
if(((p<1)||(p>n))||(p>200))
printf("enter the valid number of refreshment points\n");
else
{
int refresh_points[p+1];
refresh_points[0]=0;
refresh_points[p+1]=n;
printf("enter the locations of refreshment points");
for(i=1;i<=p;i++)
scanf("%d",&refresh_points[i]);
sort(refresh_points,p);
for(i=1;i<=p;i++)
{
temp=refresh_points[i+1]-refresh_points[i];
if(temp>diff)
diff=temp;
}
printf("%d\n",diff);
}
}
}
}
return 0;
}
void sort(int *refresh_points,int p )
{
int temp,i,j;
for(i=1;i<=p;i++)
for(j=i+1;j<=p;j++)
if((*(refresh_points+i))>(*(refresh_points+j)))
{
temp=*(refresh_points+i);
(*(refresh_points+i))=(*(refresh_points+j));
*(refresh_points+j)=temp;
}
}