Codeforces Round 975 (Div. 1)
E1
Complex Segments (Easy Version)
Codeforces
3300
原题
← DE2 →
翻译中…
翻译中…

This is the easy version of the problem. In this version, the constraints on $n$ and the time limit are lower. You can make hacks only if both versions of the problem are solved.

翻译中…

A set of (closed) segments is complex if it can be partitioned into some subsets such that

翻译中…
  • all the subsets have the same size; and
  • a pair of segments intersects if and only if the two segments are in the same subset.
翻译中…

You are given $n$ segments $[l_1, r_1], [l_2, r_2], \ldots, [l_n, r_n]$. Find the maximum size of a complex subset of these segments.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^4$) — the number of segments.

翻译中…

The second line of each test case contains $n$ integers $l_1, l_2, \ldots, l_n$ ($1 \le l_i \le 2n$) — the left endpoints of the segments.

翻译中…

The third line of each test case contains $n$ integers $r_1, r_2, \ldots, r_n$ ($l_i \leq r_i \le 2n$) — the right endpoints of the segments.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, output a single integer: the maximum size of a complex subset of the given segments.

翻译中…

Note

翻译中…

In the first test case, all pairs of segments intersect, therefore it is optimal to form a single group containing all of the three segments.

翻译中…

In the second test case, there is no valid partition for all of the five segments. A valid partition with four segments is the following: $\{\{ [1, 5], [2, 4] \}, \{ [6, 9], [8, 10] \}\}$.

翻译中…

In the third test case, it is optimal to make a single group containing all the segments except the second.

翻译中…

样例

Input #1
3
3
1 2 3
5 4 6
5
1 2 3 6 8
5 4 7 9 10
5
3 1 4 1 5
7 2 6 5 10
Output #1
3
4
4
InputCopy OutputCopy
题目信息
题号
2018E1
时间限制
6 s
内存限制
256 MB
标签
二分
数据结构
分治
并查集
贪心
数学
排序

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