рони,
There is a special kind of apple tree that grows apples every day for n days. On the ith day, the tree grows apples[i] apples that will rot after days[i] days, that is on day i + days[i] the apples will be rotten and cannot be eaten. On some days, the apple tree does not grow any apples, which are denoted by apples[i] == 0 and days[i] == 0.
You decided to eat at most one apple a day (to keep the doctors away). Note that you can keep eating after the first n days.
Given two integer arrays days and apples of length n, return the maximum number of apples you can eat.
Пример 1:
Input: apples = [1,2,3,5,2], days = [3,2,1,4,2]
Output: 7
Пояснение: вы можете съесть 7 яблок:
- В первый день вы едите яблоко. которые выросли в первый день.
- На второй день вы едите яблоко, которое выросло на второй день.
- На третий день вы едите яблоко, которое выросло на второй день. После этого дня яблоки, выросшие на третий день, загнивают.
- С четвертого по седьмой день вы едите яблоки, выросшие на четвертый день.
Пример 2:
Input: apples = [3,0,0,0,0,2], days = [3,0,0,0,0,2]
Output: 5
Пояснение: Вы можете съесть 5 яблок:
- С первого по на третий день вы едите яблоки, выросшие в первый день.
- Ничего не делайте в четвертый и пятый дни.
- На шестой и седьмой день вы едите яблоки, выросшие на шестой день.
let eatenApples = function(apples, days) {
const arr = [];
let totalApple = 0;
for(let i = 0; i < apples.length; i++) {
arr.push([i + days[i], apples[i]]);
totalApple++;
}
return totalApple;
};