题解 | #餐馆#
餐馆
http://www.nowcoder.com/practice/d2cced737eb54a3aa550f53bb3cc19d0
//按餐桌可容纳人数 升序排列 nArr.sort((a, b) => { return a - b; }); //按每批客人的 预计消费金额 升序排列 mArr.sort((a, b) => { return -(a.c - b.c); }); function fun(n, nArr, m, mArr) { let np = 0; let mp = 0; let maxMoney = 0; while(np < nArr.length && mp < mArr.length) { for(let i = 0; i < nArr.length; i++) { if (mArr[mp].b <= nArr[i]) { maxMoney += mArr[mp].c; nArr[i] = 0; np++; break; } } mp++; } return maxMoney; }