You should save dp[max(end_time)];

remember that for each end time there maybe different start times so that (end - start) are different.

Save these segments, mp[end].push_back(end-start + 1);

now check from 1 to max(end_time) and for each i,

if i is end time? then check this segments sizes,

for each such segment dp[i] = 1 + dp[i - s]; where s is saved segment sizes for end time 'i'.

https://pastebin.com/C3dagNL2 *Edited by author 30.04.2022 18:18*