Select the subset
Practice
3.7 (7 votes)
Merge sort
Sorting
Algorithms
C++
Problem
33% Success 689 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array \(A\) and \(B\) of size \(N\).
You must select a subset of indices from \(1\) to \(N\) such that for any pair of indices \((x,y), \ x \neq y\) in the subset one of the following conditions holds true:
- \(A[x] < A[y] \ \text{and} \ B[x] < B[y] \)
- \(A[x] > A[y] \ \text{and} \ B[x] > B[y] \)
- \(A[x] = A[y] \ \text{and} \ B[x] \neq B[y] \)
Your task is to determine the largest possible size of a subset that satisfies the provided conditions.
Note: Assume \(1\) based indexing.
Input format
- The first line contains an integer \(T\) that denotes the number of test cases.
- For each test case:
- The first line contains an integer \(N\).
- The second line contains \(N\) space-separated integers that denotes the array \(A\).
- The third line contains \(N\) space-separated integers that denotes the array \(B\).
Output format
For each test case, print the largest possible size of a subset that satisfies the provided conditions in a new line.
Constraints
\(1 \le T \le 10 \\ 2 \le N \le 10^5 \\ 1 \le A[i], B[i] \le 10^9\)
Submissions
Please login to view your submissions
Similar Problems
Points:30
8 votes
Tags:
AlgorithmsApprovedMediumOpen
Points:30
13 votes
Tags:
AlgorithmsGreedy AlgorithmsMerge SortSorting
Points:30
3 votes
Tags:
AlgorithmsMerge SortSorting
Editorial