Logo
(追記) (追記ここまで)

16689번 - Liars 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 512 MB (추가 메모리 없음)1361069880.992%

문제

There are n people in a circle, numbered from 1 to n, each of whom always tells the truth or always lies.

Each person i makes a claim of the form: “the number of truth-tellers in this circle is between ai and bi, inclusive.”

Compute the maximum number of people who could be telling the truth.

입력

The first line contains a single integer n (1 ≤ n ≤ 103). Each of the next n lines contains two space-separated integers ai and bi (0 ≤ ai ≤ bi ≤ n).

출력

Print, on a single line, the maximum number of people who could be telling the truth. If the given set of statements is inconsistent, print -1 instead.

제한

예제 입력 1

3
1 1
2 3
2 2

예제 출력 1

2

예제 입력 2

8
0 1
1 7
4 8
3 7
1 2
4 5
3 7
1 8

예제 출력 2

-1

힌트

출처

ICPC > Regionals > North America > Pacific Northwest Regional > 2018 Pacific Northwest Region Programming Contest > Division 1 L번

ICPC > Regionals > North America > Pacific Northwest Regional > 2018 Pacific Northwest Region Programming Contest > Division 2 Y번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /