In this HackerEarth Micro and Array Update problem solution, Micro purchased an array A having N integer values. After playing it for a while, he got bored of it and decided to update the value of its element. In one second he can increase the 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.


HackerEarth Micro and Array Update problem solution


HackerEarth Micro and Array Update problem solution.

#include<bits/stdc++.h>
using namespace std;

int main(){
    int t;cin>>t;
    while(t--){
        int n, k;cin>>n>>k;
        int ans = k;
        for(int i=1; i<=n; i++){
            int temp;cin>>temp;
            ans = min(ans, temp);
        }
        cout<<k-ans<<endl;
    }
    return 0;
}