function solution(arr,m){
let answer=0;
let n=arr.length;
arr = arr.sort((a,b)=>(a[0]+a[1])-(b[0]+b[1]));
for(let i=0; i<n; i++){
let money = m-(arr[i][0]/2)+(arr[i][1]);
let cnt = 1;
for(let j=0; j<n; j++){
let tot = arr[j][0]+arr[j][1];
if(arr[i]!==arr[j]){
if(money - tot < 0){
break;
}
if(money - tot >= 0){
money-=tot;
cnt++;
}
}
}
answer=Math.max(answer, cnt);
}
return answer;
}
let arr=[
[6,6],
[2,2],
[4,3],
[4,5],
[10,3]
]
console.log(solution(arr,28));