Skip to content

Commit 16a872c

Browse files
authored
Update 1648-sell-diminishing-valued-colored-balls.js
1 parent cdab978 commit 16a872c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

1648-sell-diminishing-valued-colored-balls.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* @return {number}
55
*/
66
const maxProfit = function(inventory, orders) {
7+
const bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
78
inventory = inventory.map(e => BigInt(e))
89
orders = BigInt(orders)
9-
let l = 0n, r = BigInt(1e9 + 7)
10+
let l = 0n, r = bigIntMax(...inventory)
1011
while(l < r) {
1112
const mid = l + (r - l) / 2n
1213
if(valid(mid)) l = mid + 1n
@@ -25,6 +26,7 @@ const maxProfit = function(inventory, orders) {
2526
res = (res + (orders - cnt) * t) % mod
2627

2728
return res
29+
2830
function valid(mid) {
2931
let res = 0n
3032
for(const e of inventory) {

0 commit comments

Comments
 (0)