You like tracking airplane flights a lot. Specifically, you maintain history of an airplane’s flight at several instants and record them in your notebook. Today, you have recorded N such records h1, h2, ..., hN, denoting the heights of some airplane at several instants. These records mean that airplane was first flying on height h1, then started changing its height to h2, then from h2 to h3 and so on. The airplanes are usually on cruise control while descending or ascending, so you can assume that plane will smoothly increase/decrease its height from hi to hi + 1 with a constant speed. You can see that during this period, the airplane will cover all possible heights in the range [min(hi, hi+1), max(hi, hi+1)] (both inclusive). It is easy to see that the plane will be at all possible heights in the range exactly a single instant of time during this ascend/descend.You are interested in finding the maximum integer K such that the plane was at some height exactly K times during the flight.

 #include <stdio.h>
int main()
{int h[100001];
int i,j,max=0,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{scanf("%d",&h[i]);
if(h[i]>max)
max=h[i];}
int s[100]={0};
for(i=0;i<n-1;i++)
{if(h[i]>h[i+1]){
for(j=h[i+1];j<h[i];j++)
    s[j]++;}
if(h[i]<h[i+1])
{for(j=h[i];j<h[i+1];j++)s[j]++;}}
int k=0;
for(j=0;j<max;j++)
{if(s[j]>k)
k=s[j];}
printf("%d",k);
return 0;}

Comments

Popular posts from this blog

Elavenil has a chessboard with N rows and M columns. In one step, he can choose two cells of the chessboard which share a common edge (that has not been cut yet) and cut this edge. Formally, the chessboard is split into two or more pieces if it is possible to partition its cells into two non-empty subsets S1 and S2 (S1∩S2=∅, |S1|+|S2|=NM) such that there is no pair of cells c1,c2 (c1∈S1,c2∈S2) which share a common edge that has not been cut.Elavenil does not want the board to split into two or more pieces. Compute the maximum number of steps he can perform while satisfying this condition.

Akash the die heart fan of AR Rahman went to the live concert happened in Bangalore with his family members.The event management firm responsible for the event arranged the seats for the audience in descending order of maximum number of tickets booked for single family.

Mahesh has given a two-dimensional 3*3 array starting from A [0][0]. You should add the alternate elements of the array and print its sum. It should print two different numbers the first being sum of A 0 0, A 0 2, A 1 1, A 2 0, A 2 2 and A 0 1, A 1 0, A 1 2, A 2 1.