#FT0000044. Mảng nhỏ nhất (Minimum Array)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mảng nhỏ nhất (Minimum Array)
Minimum Array
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given two arrays and , each of length , with all values in , you may rearrange the elements of arbitrarily. You cannot change or add or remove any occurrence from .
After rearranging , define
for . Choose the rearrangement that makes the array lexicographically smallest: first minimize , then among such choices minimize , and so on. Output the optimal array , not the rearranged array .
Input
- Line 1: integer , the common array length.
- Line 2: integers .
- Line 3: integers .
Output
Print the values of the optimal array on one line, separated by spaces.
Subtasks
Subtask 1 (20 points):
- ; for all ; repeated values are allowed.
Subtask 2 (30 points):
- ; for all ; repeated values are allowed.
Subtask 3 (50 points):
- ; for all ; repeated values are allowed.
Examples
Examples 1
Input
3
1 2 0
2 1 2
Output
0 0 2
Explanation
For , choose to make . Of the remaining values and , choose for to obtain instead of . The last value is , giving .
Examples 2
Input
4
0 0 0 0
3 1 2 1
Output
1 1 2 3
Explanation
As every , we have . Sorting the available values of in increasing order yields the lexicographically smallest .
Every element of must be used exactly once. As all and every is below , the modulo operation leaves the chosen value unchanged. The smallest available value for the first position is , then another , followed by and .