Problem Statement
Contest Source
Author , Tester and Editorialist : somashekhar001
DIFFICULTY:
Easy
PREREQUISITES:
None
PROBLEM:
we are being to find the sum of all webs used by spydy to save girl
EXPLANATION:
Checking height of adjacent building and saving number of webs used in it till last building and last find the sum of all webs saved
SOLUTION:
#include<stdio.h>
int main()
{
int T,N;
int H[1000];
int S[1000];
int count=0;
scanf("%d%d",&T,&N);//taking input of T and N
for(int i=0;i<N;i++)
{
scanf("%d",&H[i]);//taking input of heights of buildings
}
int sum=1;//for jumping to first building H[0]
for(int i=0;i<N-1;i++)
{
if(H[i+1]>H[i]) //checking height of adjacent building
{
sum++;
S[count]=sum;//S array is saving number of web thrown for adjacent buildings of greater height
count++;
}
else
{
sum=1;
S[count]=sum;//S array is saving number of web thrown for adjacent buildings of same height or less height
count++;
}
}
int n=1; //for jumping to first building H[0]
for(int j=0;j<count;j++)
{
n=n+S[j]; //number of total web thrown is sum of webs thrown for each building
}
if(T>=n)//each web takes 1 unit time then spiderman to reach girl takes n unit of time so checking if he reach the girl or not
{
printf("YES");
}
else
{
printf("NO");
}
return 0;
}