```
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
if(timeSeries.size()==0) return 0;
int res=0, end=timeSeries[0];
for(int i=0;i<timeSeries.size();i++) {
if(timeSeries[i]>end) res+=duration;
else if(i>0) res+=timeSeries[i]-timeSeries[i-1];
end=timeSeries[i]+duration-1;
}
res+=duration;
return res;
}
```