Sort both arrays. Give the smallest sufficient cookie to the least greedy unsatisfied child. Why? If a small cookie can satisfy multiple children, give it to the least greedy one. Save larger cookies for greedier children. Using a big cookie on an easily-satisfied child wastes potential.
Here's optimal because you never waste a cookie that could satisfy someone harder to satisfy.