cswork / OAOpen practice workspace

IBMOA #65

Rearrange Server Load

Estimated EasyJudge-ready

Topics (AI-labelled)GreedyIn-place Arrays

With serverCapacity fixed, rearrange serverLoad to minimize Σ capacity[i]×load[i]. If there are multiple minimum-resource arrangements, you must return the lexicographically smallest load array. The latter requirement comes directly from the original statement body; the compiled catalog lost that sentence.

Input

The first line contains n, the second line contains n capacity values, and the third line contains n load values. This site adds 1≤n≤200000, and the elements of both arrays are integers in −10^9..10^9, with duplicates and negative values allowed.

Output

Output n integers: the unique lexicographically smallest optimal load arrangement.

Example 1

Input:

3
4 5 6
1 2 3

Output:

3 2 1

Example 2

Input:

5
1 2 3 3 3
2 2 4 5 6

Output:

6 5 2 2 4

Example 3

Input:

2
1 1
2 1

Output:

1 2

Example notes

The outputs of the three public examples are, in order: 3 2 1; 6 5 2 2 4; 1 2. These answers were verified by independent enumeration or direct simulation.

Editorial

Loading solution…