import Foundation
func solution(_ d:[Int], _ budget:Int) -> Int {
var sum = [Int]()
let d = d.sorted()
for c in d {
sum.append(c)
if sum.reduce(0, +) > budget {
sum.removeLast()
break
}
}
return sum.count
}
import Foundation
func solution(_ d:[Int], _ budget:Int) -> Int {
var budget = budget
return d.sorted().filter {
budget = budget - $0
return budget >= 0
}.count
}