Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- const long max = 100;
- bool t;
- long i,j,p1,p2,ma;
- long n[max];
- long a[max][max],b[max][max];
- int main()
- {
- i = 0;
- while ((scanf("%li\n",&n[i])) == 1) {
- for (j=0;j<n[i];j++) {
- scanf("%li %li\n",&a[i][j],&b[i][j]);
- if (b[i][j] == 0) {
- b[i][j] = a[i][j];
- }
- }
- i += 1;
- }
- ma = i;
- for (i = 0;i<ma;i++) {
- t = true;
- p1 = a[i][0];
- p2 = b[i][0];
- for (j=0;j<n[i];j++) {
- if (a[i][j]>=p1 and b[i][j]<=p2) {
- p1 = a[i][j];
- p2 = b[i][j];
- }
- else
- if (a[i][j]<=p1 and b[i][j]>=p2) {
- p1 = p1;
- p2 = p2;
- }
- else
- if (a[i][j]<=p1 and b[i][j]<=p2 and b[i][j]>=p1) {
- p1 = p1;
- p2 = b[i][j];
- }
- else
- if (a[i][j]>=p1 and b[i][j]>=p2 and p2>=a[i][j]) {
- p1 = a[i][j];
- p2 = p2;
- }
- else
- {
- t = false;
- break;
- }
- }
- if (t == true) {
- printf("YES\n");
- }
- else
- printf("NO\n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment