Header Ads Widget

Eerie Planet

 Problem:-

You own a club on eerie planet. The day on this planet comprises of H hours. You appointed C crew members to handle the huge crowd that you get, being the best club on the planet. Each member of the crew has fixed number of duty hours to work. There can be multiple or no crew members at work at any given hour of the day.
Being on weird planet, the rules of this club cannot be normal. Each member of the crew only allows people who are taller than him to enter the club when he is at work.
Given the schedule of work and heights of the crew members, you have to answer Q queries. Each query specifies the time of entry and height of a person who is visiting the club. You have to answer if the person will be allowed to enter the club or not.

Input:
First line of the input contains 3 integers, H,C,Q. Representing number of hours in a day, number of crew members and number of queries respectively.
Next C lines follow, where each line contains 3 integers, hi,Si,Ei, representing height of the crew member and start and end hour of his/her work schedule. He/she works for hours [Si,Ei], both inclusive.
Next Q lines follow, each containing 2 integers, hi,ti, representing height and time (in hour) of the person trying to enter the club.

Output:
Q lines, each line containing "YES" or "NO", without the quotes, answering if the person will be allowed to enter the club or not.

Constraints:
1H109
1C105
1Q105
1SiEiH
1tiH
1hi107

Sample Input
10 1 5
50 2 6
10 1
10 2
50 5
51 6
100 10
Sample Output
YES
NO
NO
YES
YES
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

During the first hour, there is no crew member and hence person is allowed.
During hours 2 and 5, person is not taller than crew member, hence is not allowed to enter.
4th person is taller than the crew member at work and hence person is allowed.
During the 10th hour, there is no crew member and hence person is allowed.

Solution:-

#include<stdio.h>
int main()
{
  long long int i,j,t,H,C,height,Q,S[100000],E[100000],h[100000];
  long long int nc=0,val=0,flag=0,maximum_height=0;
  scanf("%lld%lld%lld",&H,&C,&Q);
  
  for(i=0;i<C;i++)
  {
    scanf("%lld%lld%lld",&h[i],&S[i],&E[i]);
    if(h[i]>maximum_height)
     maximum_height=h[i];
  }

  for(i=0;i<Q;i++)
  {
    scanf("%lld%lld",&height,&t);
    if(height>maximum_height)
     printf("YES\n");
    else{
    val=0;
    nc=0;
    flag=0;
    for(j=0;j<C;j++)
    { 
      if(t>=S[j] && t<=E[j])
      {
        nc++;
        if(height<=h[j])
        {
         printf("NO\n");
         flag=1;
         break;
        }
        else
         val++;
      } 
    }
  
    if(nc==val)
     printf("YES\n");
    else
     if(flag==0)
     printf("NO\n");
    }
    
  }
  return 0;
}



Post a Comment

0 Comments