paradox64ce

assign05.c

Feb 11th, 2020
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Name:Mayank Kumar
  3. Roll no:1901CB24
  4. Assignment No.5
  5. */
  6.  
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. int n;
  12. int s_c,e_c;
  13. int min(int a,int b)
  14. {
  15.  return (a<b)?a:b;
  16. }
  17.  
  18. int people_in_interval(int s[],int e[],int t1,int t2)//method for finding number of people in the interval
  19. {
  20.  int p_t=0;
  21.  for(int i=0;i<n;i++)//iterating over all people
  22.     {
  23.       if(!(e[i]<t1 || s[i]>t2))
  24.       {
  25.         p_t++;
  26.       }
  27.     }
  28.     return p_t;
  29. }
  30.  
  31. void check_crime(int pi,int pj,int h,int s[],int e[])//method for checking if 2 people can commit crime or not
  32. {
  33.     pi--;
  34.     pj--;
  35.  
  36.     if((s[pi]>=e_c || e[pi]<=s_c) || (s[pj]>=e_c || e[pj]<=s_c))
  37.     {
  38.       printf("NO\n");
  39.     }
  40.     else{
  41.      int tc=0;
  42.      if((s[pi]>=s[pj] && e[pi]<=e[pj]) || (s[pj]>=s[pi] && e[pj]<=e[pi]))
  43.      {
  44.       tc=min(e[pj]-s[pj],e[pi]-s[pi]);
  45.       if(tc>=h)
  46.       {
  47.         printf("YES\n");
  48.       }
  49.       else{
  50.        printf("NO\n");
  51.       }
  52.      }  else if((e[pi]<s[pj]) || (e[pj]<s[pi]))
  53.      {
  54.       printf("NO\n");
  55.      }
  56.      else{
  57.  
  58.      if(s[pi]<=s[pj])
  59.      {
  60.        tc=e[pi]-s[pj];
  61.      }
  62.      else{
  63.       tc=e[pj]-s[pi];
  64.      }
  65.      if(tc>=h)
  66.       {
  67.         printf("YES\n");
  68.       }
  69.       else{
  70.        printf("NO\n");
  71.       }
  72.  
  73.      }
  74.     }
  75. }
  76. int main()
  77. {
  78.  
  79.     scanf("%d%d",&s_c,&e_c);
  80.     scanf("%d",&n);
  81.     int s[n],e[n];
  82.     for(int i=0;i<n;i++)
  83.     {
  84.      scanf("%d %d",&s[i],&e[i]);
  85.     }
  86.  
  87.     int p_abs=n-people_in_interval(s,e,s_c,e_c);//invocing method for finding number of people in the interval
  88.     printf("%d\n",p_abs);
  89.  
  90.     int h;
  91.     scanf("%d",&h);
  92.     int t1,t2;
  93.     scanf("%d %d",&t1,&t2);
  94.  
  95.     printf("%d\n",people_in_interval(s,e,t1,t2));//invocing method for finding number of people in the interval
  96.  
  97.     int pi,pj;
  98.     scanf("%d %d",&pi,&pj);
  99.  
  100.     check_crime(pi,pj,h,s,e);//checking if 2 people can commit crime or not
  101.  
  102.     return 0;
  103. }
RAW Paste Data