The Hurdle Race-Hackerrank

problem statement:
Dan is playing a video game in which his character competes in a hurdle race. Hurdles are of varying heights, and Dan has a maximum height he can jump. There is a magic potion he can take that will increase his maximum height by 1 unit for each dose. How many doses of the potion must he take to be able to jump all of the hurdles.
INPUT:
Given an array of hurdle heights" height" and an initial maximum height Dan can jump,K , determine the minimum number of doses Dan must take to be able to clear all the hurdles in the race.
Example

It is recommended to solve this problem using this link before seeing the solution.
https://www.hackerrank.com/challenges/the-hurdle-race/problem

EXPLANATION:
Here the input is a array of heights .According to problem statement ,there is a limit up to which Dan can jump and there is a potion which gives strength to climb plus one height for one dose ,so the solution will be difference between maximum height and limit of Dan, because if Dan can climb the maximum height ,then he can climb all other heights.
APPROACH
use a maximum variable to find maximum variable and print difference between maximum value and Dan's limit only if maximum value is greater than Dan's limit.
If Dan's limit is greater than maximum value then print ZERO because he doesn't need to take any potion.
CODE
int main ( )
{
int array[200],i,max=0,n,limit;
scanf("%d %d",&n,&limit);// take input of length of height array and limit of dan
for(i=n-1;i>=0;i--)
scanf("%d",&array[i]);//read elements to array
for(i=n-1;i>=0;i--)
if(array[i]>max)//if maximum value up to now is less than present value then maximum will be present value
max=array[i];
if(limit>max)//If dan has enough strength to climb then he doesn't need any otion so ZERO
printf("0");
else//Dan doesn't have enough strength so print difference
printf("%d",max-limit);
return 0;
}
This can be solved using a sorted array to find maximum but that is not required here in the previous approach maximum value can be found using one for loop but for sorting we need two for loops so this method is efficient.
HOPE THIS HELPS..........
HAPPY CODING...........