#P16250. [蓝桥杯 2026 省研究生组] 人类识别审查

[蓝桥杯 2026 省研究生组] 人类识别审查

Problem Description

In the year 2145, the world passed the "Synthetic Human Control Act". All suspected disguised high-bionic AI must undergo a "human identification review".

In the interrogation room of Xingang District, Xiaolan stared at the list projected on the table: there are a total of NN "agents" in the room, whose appearance and behavior are almost indistinguishable from humans. Some are real humans, and some are humanoid AI in disguise.

The review rules are as follows:

  1. Let the number of real humans in the room be KK (KK is an integer satisfying 0KN0 \leq K \leq N).
  2. The ii-th agent gives a testimony: "The number of humans is within the interval [ai,bi][a_i, b_i]."
  3. If an agent is a real human, then its testimony must be true, i.e., aiKbia_i \leq K \leq b_i.
  4. If an agent is a disguised AI, then its testimony must be false, i.e., K[ai,bi]K \notin [a_i, b_i].

As Xiaolan's assistant, please analyze all testimonies and compute the maximum possible number of humans in the room (i.e., the largest possible value of KK). If there is no logically consistent KK, output 1-1.

Input Format

The first line contains an integer NN, representing the number of agents in the room.

The next NN lines each contain two integers ai,bia_i, b_i, representing the interval of the number of humans claimed by the ii-th agent.

Output Format

Output one integer, the maximum KK that satisfies the conditions; if there is no solution, output 1-1.

3
1 2
2 3
3 3
2
3
1 1
1 1
1 1
0
1
0 0
-1

Hint

【Constraints and Conventions】

For 30%30\% of the testdata, 1N1031 \leq N \leq 10^3, 0aibiN0 \leq a_i \leq b_i \leq N.

For all testdata, 1N1051 \leq N \leq 10^5, 0aibiN0 \leq a_i \leq b_i \leq N.

Translated by ChatGPT 5