1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| func maxSatisfied(customers []int, grumpy []int, minutes int) int { n := len(customers) sum := 0 saveCustomer := 0 for i := 0; i < minutes; i++ { if grumpy[i] == 1 { saveCustomer += customers[i] } else { sum += customers[i] } } ans := saveCustomer for i := minutes; i < n; i++ { if grumpy[i-minutes] == 1 { saveCustomer -= customers[i-minutes] } if grumpy[i] == 1 { saveCustomer += customers[i] } else { sum += customers[i] } ans = max(ans, saveCustomer) } return ans + sum }
|