DeepInfra Round 1(Codeforces Round 1126,Div. 1 + Div. 2)
D
目标感染人数
Target Infection
Codeforces
1700
原题
← CE →

目标感染人数AI (CI翻译)

You are given $n$ pairwise disjoint infection intervals on the number line. The $i$-th interval is $[l_i, r_i]$, meaning that every integer position $x$ such that $l_i \le x \le r_i$ is infected. All integer positions not covered by any of the intervals are not infected.

给定数轴上 $n$ 个两两不相交的感染区间。第 $i$ 个区间为 $[l_i, r_i]$,表示所有满足 $l_i \le x \le r_i$ 的整数位置 $x$ 均被感染。所有未被任何区间覆盖的整数位置均未被感染。AI (CI翻译)

There are $m$ people standing in a row. If the first person stands at position $s$, then the people stand at positions $s, s + 1, \ldots, s + m - 1$. A person is infected if the position they stand at is infected.

有 $m$ 个人站成一排。如果第一个人站在位置 $s$,那么这些人分别站在位置 $s, s + 1, \ldots, s + m - 1$。如果一个人所站的位置被感染,那么这个人就被感染。AI (CI翻译)

For an integer $s$, let $f(s)$ be the number of infected people when the first person stands at position $s$.

对于整数 $s$,定义 $f(s)$ 为第一个人站在位置 $s$ 时被感染的人数。AI (CI翻译)

You are given an integer $k$. Find any integer $s$ such that $f(s) = k$, or determine that no such $s$ exists.

给定一个整数 $k$。请找出任意一个满足 $f(s) = k$ 的整数 $s$,或判断这样的 $s$ 不存在。AI (CI翻译)

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

每个输入包含多组测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^4$)。接下来是各组测试用例的描述。AI (CI翻译)

The first line of each test case contains three integers $n$, $m$, and $k$ ($1 \le n \le 2 \cdot 10^5$, $1 \le m \le 10^9$, $0 \le k \le m$) — the number of infection intervals, the number of people, and the required number of infected people.

每组测试用例的第一行包含三个整数 $n$、$m$ 和 $k$($1 \le n \le 2 \cdot 10^5$,$1 \le m \le 10^9$,$0 \le k \le m$)——分别表示感染区间的数量、总人数以及要求的感染人数。AI (CI翻译)

The $i$-th of the following $n$ lines contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le 10^{15}$) — the endpoints of the $i$-th infection interval. It is guaranteed that $r_i + 1 \lt l_{i + 1}$ for every $i$ from $1$ to $n - 1$, so the intervals are pairwise disjoint, no two of them are adjacent, and they are given from left to right.

接下来的 $n$ 行中,第 $i$ 行包含两个整数 $l_i$ 和 $r_i$($1 \le l_i \le r_i \le 10^{15}$)——表示第 $i$ 个感染区间的端点。保证对于从 $1$ 到 $n - 1$ 的每个 $i$,都有 $r_i + 1 \lt l_{i + 1}$,因此这些区间两两不相交,任意两个区间均不相邻,且按从左到右的顺序给出。AI (CI翻译)

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, if there is no integer $s$ such that $f(s) = k$, output $-1$.

对于每组测试用例,如果不存在满足 $f(s) = k$ 的整数 $s$,输出 $-1$。AI (CI翻译)

Otherwise, output a single integer $s$ ($1 \le s \le 10^{18}$) — a position such that $f(s) = k$. It can be shown that if at least one such position exists, then a position within these bounds exists as well.

否则,输出一个整数 $s$($1 \le s \le 10^{18}$)——表示一个满足 $f(s) = k$ 的位置。可以证明,如果至少存在一个满足条件的位置,那么在上述范围内也一定存在满足条件的位置。AI (CI翻译)

If there are multiple valid positions, output any of them.

如果有多个合法位置,输出任意一个即可。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first example, one valid position is $s = 7$. The people then stand at the positions $7, 8, 9, 10, 11$, all of which are infected, so $f(7) = 5$.

在第一个样例中,一个合法位置是 $s = 7$。此时,这些人分别站在位置 $7, 8, 9, 10, 11$,这些位置均被感染,因此 $f(7) = 5$。AI (CI翻译)

In the second example, it can be shown that there is no suitable position.

在第二个样例中,可以证明不存在满足条件的位置。AI (CI翻译)

In the third example, one valid position is $s = 2$. The people then stand at the positions $2, 3, 4, 5, 6$. Positions $2$, $3$, $5$, and $6$ are infected, while position $4$ is not, so $f(2) = 4$.

在第三个样例中,一个合法位置是 $s = 2$。此时,这些人分别站在位置 $2, 3, 4, 5, 6$。位置 $2$、$3$、$5$ 和 $6$ 被感染,而位置 $4$ 未被感染,因此 $f(2) = 4$。AI (CI翻译)

样例

Input #1
6
1 5 5
7 11
2 4 3
1 2
5 6
3 5 4
1 3
5 6
8 8
1 3 2
10 12
3 6 0
1 1
4 5
10 12
1 1000000000 1
1000000000000000 1000000000000000
Output #1
7
-1
2
9
42
999999876543210
InputCopy OutputCopy
题目信息
题号
2271D
时间限制
2 s
内存限制
256 MB
标签
二分
暴力
贪心
模拟
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。