#include <solution/2410.h>
#include <stdbool.h>
#include <stdlib.h>

int cmp(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}

int matchPlayersAndTrainers(int *players, int playersSize, int *trainers, int trainersSize)
{
    qsort(trainers, trainersSize, sizeof(int), cmp);
    qsort(players, playersSize, sizeof(int), cmp);

    int match = 0;
    for (int i = 0, j = 0; i < playersSize && j < trainersSize; i++)
    {
        for (; j < trainersSize; j++)
        {
            if (trainers[j] >= players[i])
            {
                match++;
                j++;
                break;
            }
        }
    }

    return match;
}
