Question description kkalaiselvan is going to behave as a vehicle driver. he needs to drive an automobile on a track divided into "N" no. of sub-tracks. The letter "K" is also assigned to you. i.e. the maximum number of kilometres a vehicle may go on each sub-track. You can add any unit of Petrol to the automobile if it can't cover a sub-track. The total kilometres your automobile may go increases by one unit for every unit of gasoline added.
C Program


#include<stdio.h>

void sort(int a[],int n)

{

    int i,j,temp;

    for(i=0;i<n-1;i++)

    {

        for(j=i+1;j<n;j++)

        {

            if(a[i]>a[j])

            {

                temp=a[i];

                a[i]=a[j];

                a[j]=temp;

            }

        }

    }

}

int main()

{

    int T,n,k,i;

    scanf("%d",&T);

    while(T--)

    {

        scanf("%d %d",&n,&k);

        int a[n];

        for(i=0;i<n;i++)

            scanf("%d",&a[i]);

        sort(a,n);

        int petrol=a[n-1]-k;

        if(petrol<=0)

            printf("-1\n");

        else

            printf("%d\n",petrol);

    }

    return 0;

}