fork download
  1. program flappybird;
  2. const Max =100000;
  3. var N, i : Longint;
  4. A, B : array[0..MAX] of int64;
  5. inizio, fine :int64;
  6. uscita:boolean;
  7. begin
  8. readln(N);
  9. for i:=0 to N-1 do readln(A[i],B[i]);
  10. inizio:=A[0]; fine:=B[0]; uscita:=true;
  11. for i:=1 to N-1 do
  12. begin
  13. if (A[i]>=inizio ) and (A[i]<=fine) then begin inizio:=A[i]; if B[i]<=fine then fine:=B[i]; end
  14. else begin if A[i]>fine then begin uscita:=false; writeln ('NO'); exit; end
  15. else if A[i]<inizio then begin if B[i]<inizio then begin uscita:=false; writeln ('NO'); exit; end
  16. else if (B[i]>=inizio) and (B[i]<=fine) then fine:=B[i];
  17. end;
  18. end;
  19. end;
  20. if uscita=true then writeln('YES') ;
  21. end.
Success #stdin #stdout 0s 5316KB
stdin
4
4 7
5 6
1 3
3 6

stdout
NO