-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution1599.java
More file actions
22 lines (22 loc) · 807 Bytes
/
Copy pathSolution1599.java
File metadata and controls
22 lines (22 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution1599 {
public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {
if (4 * boardingCost - runningCost < 0) return -1;
int remain = 0, sum = 0;
int profit = 0;
for (int i = 0; i < customers.length; i++) {
remain += customers[i];
int cur = Math.min(remain - sum, 4);
sum += cur;
profit += cur * boardingCost - runningCost;
}
int times = 0;
while(remain - sum >= 4) {
int cur = Math.min(remain - sum, 4);
sum += cur;
profit += cur * boardingCost - runningCost;
times++;
}
if ((remain - sum) * boardingCost > runningCost) times++;
return profit > 0 ? customers.length + times : -1;
}
}