```ts
export function fitBudget(prices: number[], budget: number): number {
  if (budget < 0) throw new Error('Amount to spend must be non-negative');

  let totalSpent = 0;
  let count = 0;

  prices.sort((a, b) => a - b);

  for (const price of prices) {
    if (totalSpent + price > budget) break;
    totalSpent += price;
    count++;
  }

  return count;
}
```