Skip to content

lavanyamurthi/micro-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

  1. Micro and Array Update Micro purchased an array A having N integer values. After playing it for a while, he got bored of it and decided to update value of its element. In one second he can increase value of each array element by 1. He wants each array element's value to become greater than or equal to K. Please help Micro to find out the minimum amount of time it will take, for him to do so.

Input: First line consists of a single integer, T, denoting the number of test cases. First line of each test case consists of two space separated integers denoting N and K. Second line of each test case consists of N space separated integers denoting the array A.

Output: For each test case, print the minimum time in which all array elements will become greater than or equal to K. Print a new line after each test case.

constraints: 1<=T<=5

         1<=N<=10^5
         
         1<=A[i],K<=10^6

Answer:

#include<stdio.h>

int main()

{

int t,n,i,min=10000000000,k;

scanf("%d",&t);

while(t--)

{

min=10000000000;

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

int a[n];

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

{

scanf("%d",&a[i]);
  
if(a[i]<min)
   
min=a[i];

}

//printf("%d ",min);

if(min>=k)

printf("0\n");

else

printf("%d\n",k-min);

}

return 0;

}

Input:
2
3 4 1 2 5 3 2 2 5 5

output: 3 0

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published