using
System;
using
System.Collections.Generic;
public
class
GFG
{
public
static
void
anyPermutation(
int
[] A,
int
[] B,
int
n)
{
List<
int
[]> Ap =
new
List<
int
[]>();
List<
int
[]> Bp =
new
List<
int
[]>();
for
(
int
i = 0; i < n; i++)
{
Ap.Add(
new
int
[]{A[i], i});
}
for
(
int
i = 0; i < n; i++)
{
Bp.Add(
new
int
[]{B[i], i});
}
Ap.Sort((x,y)=> (x[0] != y[0]) ? x[0] - y[0] : y[1] - y[1]);
Bp.Sort((x,y)=> (x[0] != y[0]) ? x[0] - y[0] : y[1] - y[1]);
var
ii = 0;
var
j = 0;
int
[] ans =
new
int
[n];
var
remain =
new
List<
int
>();
while
(ii < n && j < n)
{
if
(Ap[ii][0] > Bp[j][0])
{
ans[Bp[j][1]] = Ap[ii][0];
ii++;
j++;
}
else
{
remain.Add(ii);
ii++;
}
}
j = 0;
for
(
var
i = 0; i < n; ++i)
{
if
(ans[i] == 0)
{
ans[i] = Ap[remain[j]][0];
j++;
}
}
for
(
var
i = 0; i < n; ++i)
{
Console.Write(ans[i].ToString() +
" "
);
}
}
public
static
void
Main(String[] args)
{
int
[] A = {12, 24, 8, 32};
int
[] B = {13, 25, 32, 11};
var
n = A.Length;
GFG.anyPermutation(A, B, n);
}
}