using
System;
using
System.Collections.Generic;
namespace
GFG
{
class
Program
{
static
void
operations(
int
n,
long
[] A,
long
[] B)
{
SortedSet<
long
> tree
=
new
SortedSet<
long
>();
Dictionary<
long
,
int
> freqMap
=
new
Dictionary<
long
,
int
>();
for
(
int
j = 0; j < n; j++)
{
long
x = A[j];
tree.Add(x);
if
(freqMap.ContainsKey(x))
{
freqMap[x] = freqMap[x] + 1;
}
else
{
freqMap[x] = 1;
}
}
for
(
int
j = 0; j < n; j++)
{
long
x = B[j];
if
(tree.GetViewBetween(x,
long
.MaxValue).Count > 0)
{
Console.Write(tree.GetViewBetween(x,
long
.MaxValue).Min +
" "
);
if
(freqMap[tree.GetViewBetween(x,
long
.MaxValue).Min] == 1)
{
tree.Remove(tree.GetViewBetween(x,
long
.MaxValue).Min);
}
else
{
freqMap[tree.GetViewBetween(x,
long
.MaxValue).Min] =
freqMap[tree.GetViewBetween(x,
long
.MaxValue).Min] - 1;
}
}
else
{
Console.Write(
"null "
);
}
}
}
static
void
Main(
string
[] args)
{
int
n = 12;
long
[] A =
new
long
[] { 9, 5, 100, 4,
89, 2, 0, 2,
89, 77, 77, 77 };
long
[] B =
new
long
[] { 0, 18, 60, 34,
50, 29, 4, 20,
48, 77, 2, 8 };
operations(n, A, B);
}
}
}