Vladislav_Bezruk

Some task

Oct 13th, 2020 (edited)
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. const long max = 100;
  4.  
  5. bool t;
  6. long i,j,p1,p2,ma;
  7. long n[max];
  8. long a[max][max],b[max][max];
  9.  
  10.  
  11. int main()
  12. {
  13.  
  14.   i = 0;
  15.   while ((scanf("%li\n",&n[i])) == 1) {
  16.        
  17.     for (j=0;j<n[i];j++) {
  18.        
  19.     scanf("%li %li\n",&a[i][j],&b[i][j]);
  20.    
  21.     if (b[i][j] == 0) {
  22.         b[i][j] = a[i][j];
  23.       }
  24.        
  25.      }
  26.    
  27.   i += 1;  
  28.   }
  29.  
  30.   ma = i;
  31.  
  32.   for (i = 0;i<ma;i++) {
  33.    
  34.     t = true;
  35.     p1 = a[i][0];
  36.     p2 = b[i][0];
  37.    
  38.     for (j=0;j<n[i];j++) {
  39.        
  40.         if (a[i][j]>=p1 and b[i][j]<=p2) {
  41.            
  42.             p1 = a[i][j];
  43.             p2 = b[i][j];
  44.                
  45.           }
  46.           else
  47.             if (a[i][j]<=p1 and b[i][j]>=p2) {
  48.            
  49.             p1 = p1;
  50.             p2 = p2;
  51.                
  52.           }
  53.         else
  54.             if (a[i][j]<=p1 and b[i][j]<=p2 and b[i][j]>=p1) {
  55.            
  56.             p1 = p1;
  57.             p2 = b[i][j];
  58.                
  59.           }
  60.         else
  61.             if (a[i][j]>=p1 and b[i][j]>=p2 and p2>=a[i][j]) {
  62.            
  63.             p1 = a[i][j];
  64.             p2 = p2;
  65.                
  66.           }
  67.           else
  68.           {
  69.           t = false;
  70.           break;           
  71.           }
  72.                
  73.       }
  74.    
  75.     if (t == true) {
  76.         printf("YES\n");
  77.       }
  78.       else
  79.         printf("NO\n");
  80.   }
  81.  
  82.     return 0;
  83. }
Add Comment
Please, Sign In to add comment