using System;
public class Program
{
public static void Main()
// Test Case #1
int spend1 = 50;
int[] a = {1,12,5,111,200,1000,10};
Console.WriteLine(maximumToys(a, spend1)); // 4
// Test Case #2
int spend2 = 7;
int[] b = {1,2,3,4};
Console.WriteLine(maximumToys(b, spend2)); // 3
// Test Case #3
int spend3 = 15;
int[] c = {3,7,2,9,4};
Console.WriteLine(maximumToys(c, spend3)); // 3
}
// Complete the maximumToys function below.
static int maximumToys(int[] prices, int k) {
int total = 0;
int ans = 0;
// Sort the array
Array.Sort(prices);
// loop through adding up the toys until k is exceeded
foreach(int a in prices)
if(total + a < k)
total += a;
ans++;
else
return ans;