#P16703. [SEATST 2026] 两场考试 / Two Exams
[SEATST 2026] 两场考试 / Two Exams
Problem Description
There are students in the class. Each student is assigned an ID from to based on the current class ranking. That is, student (for all ) currently has class rank . Here, rank is the best, and rank is the worst.
The class has recently finished Chinese and Math exams. Student (for all ) has rank in the Chinese exam and rank in the Math exam. Both and are permutations of length .
:::info[What is a permutation of length ?]{open} In this problem, a permutation of length is an array of length such that for all , we have , and for all , we have .
For example, is a permutation of length , but and are not permutations of length . :::
The teacher wants to re-rank all students. The new ranking can be represented by a permutation .
For each student , their new class rank must satisfy at least one of the following conditions:
- For all such that , student has a better Chinese score than student (i.e., ), or
- For all such that , student has a better Math score than student (i.e., ).
:::warning[Warning]{open} This condition only applies to those with . There are no restrictions for those with .
For each student , when checking whether the condition is satisfied, you must first choose one subject, and then compare student with all the corresponding students using that subject. For the same , all different must be better than student in the same subject. You cannot switch subjects halfway through when evaluating the condition for student . :::
The dissatisfaction of the new class ranking is defined as the maximum amount of rank drop among all students. In other words, dissatisfaction is the maximum value of (for all ).
:::warning[Warning]{open} Dissatisfaction is the maximum of . The value of does not affect the calculation of dissatisfaction. :::
Among all possible new rankings, find the minimum possible dissatisfaction.
Implementation Details
You need to implement the following function:
int minimum_dissatisfaction(int N, std::vector<int> A, std::vector<int> B)
- : the number of students.
- : an array of length , representing the ranks in the Chinese exam.
- : an array of length , representing the ranks in the Math exam.
- This function should return the minimum dissatisfaction of the new class ranking.
- This function is called exactly once for each testdata.
Input Format
N
A[0] A[1] ... A[N - 1]
B[0] B[1] ... B[N - 1]
Output Format
A single integer, which is the return value of minimum_dissatisfaction.
Hint
Sample
Consider the following function call:
minimum_dissatisfaction(5, [3, 0, 4, 1, 2], [0, 3, 2, 4, 1])
In this example, one way to assign the new ranking is .
Consider student , with . All students such that have a better Math rank than student , so this student satisfies the class ranking condition.
Next, consider student , with . All students such that have a better Chinese rank than student , so this student also satisfies the class ranking condition.
It can be verified that all other students also satisfy the class ranking condition.
The dissatisfaction of this new ranking is . There is no other new ranking with lower dissatisfaction, so the function should return .
Constraints
- .
- For all , .
- For all , .
- For all , .
Subtasks
- ( points) .
- ( points) .
- ( points) .
- ( points) , and for all , .
- ( points) .
- ( points) , and for all , .
- ( points) .
- ( points) no additional constraints.
Note: For subtask , the judging program alone is guaranteed to take milliseconds out of the milliseconds time limit.
Translated by ChatGPT 5