求翻译,玄关
  • 板块灌水区
  • 楼主ChenZQ
  • 当前回复19
  • 已保存回复19
  • 发布时间2023/8/17 20:13
  • 上次更新2023/11/3 03:03:18
查看原帖
求翻译,玄关
745358
ChenZQ楼主2023/8/17 20:13

Cartoons

题目描述

Tanya likes cartoons. She knows that nn new cartoons will be released in his favorite cinema: the ii -th of them will be airing from the day aia_i to the day bib_i ( 1≤ai≤bi≤1091 \le a_i \le b_i \le 10^9 ).

The cinema has a special offer: there is a huge discount every day when only one cartoon is airing.

Tanya doesn't care which cartoon she will watch but she'd like to save some money. That's why she asks you to find any day xx when only one cartoon will be airing. Formally: find xx such that there is exactly one ii ( 1≤i≤n1 \le i \le n ) with ai≤x≤bia_i \le x \le b_i . If there are several possible answers, print any of them. If there is no such day, print -1.

输入格式

The first line contains single integer tt ( 1≤t≤10001 \le t \le 1000 ) — the number of test cases. The following are descriptions of the tt test cases.

The first line of each test case contains a single integer nn ( 1≤n≤20001 \le n \le 2000 ) — the number of cartoons.

In the next nn lines, the cartoons themselves are described, one per line, by a pair of integers aia_i , bib_i ( 1≤ai≤bi≤1091 \le a_i \le b_i \le 10^9 ) — the first and last airing days for the ii -th cartoon.

It is guaranteed that the sum of the values nn for all test cases in the input does not exceed 20002000 .

输出格式

Print tt answers to given test cases in the order in which they appear in the input: the ii -th answer is such xx , that only one cartoon will be airing on day xx or -1 if there are no such days.

样例 #1

样例输入 #1

5
1
1 1
3
2 1000000000
2 500000000
500000002 1000000000
3
1 2
3 4
1 4
2
4 11
4 9
3
1 5
10 10
1 5

样例输出 #1

1
500000001
-1
10
10

提示

In the third test case: at day 11 and 22 , first and third cartoons will be airing, and days 33 and 44 , second and third cartoons will be airing. So, there is no day when only one cartoon will be airing.

In the fourth test case, 1111 is also a possible answer.

2023/8/17 20:13
加载中...