```
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
int n = timeSeries.size();
if (n < 1) {
return 0;
}
int sum = duration;
for (int i = n - 2; i >= 0; i--) {
sum += (timeSeries[i + 1] - timeSeries[i] >= duration) ?
duration : (timeSeries[i + 1] - timeSeries[i]);
}
return sum;
}
```