For example, with
k=10
A=[2,1,3]
B=[7,8,9]
the answer is yes because you can re-arrage the elements to be
A=[1,2,3]
B=[9,8,7]
which then it's true that A[i]+B[i] >= 10 = k
for i=0,1,2
. My algorithm is greedy, like
int k = parameters[1];
int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), Int32.Parse);
int?[] B = Array.ConvertAll(Console.ReadLine().Split(' '), Extensions.ToNullableInt);
Array.Sort(B);
for(int j = 0; j < A.Length; ++j)
{
bool found = false;
for(int m = 0; j < B.Length && !found; ++j)
{
if(B[m] == null)
continue;
if((A[j] + B[m]) >= k)
{
found = true;
B[m] = null;
}
}
if(!found)
{
Console.WriteLine("NO");
return;
}
}
Console.WriteLine("YES");
and I can't think of any cases it would fail.