What is wrong with my code

Hey please explain your algo

i know the compare and sorting has to be done but why my own method was giving the answer in compilation and not working for test cases

Thats why I asked you to explain your algorithm so that I can tell you for which testcases it will faill

I gave coding blocks ide link of the program in description

Bro I am having difficulty understanding your code and knowing you algorithm will make it more readable.

I used a pair array I was just made all comparison conditions in the if ()and then printed the maximum no . Of tasks possible for each element as reference and then found the maximum of them all

(ms) is max of them all

Explain your conditions:
(p[j].first>=p[i].second||p[j].second<=p[i].first)&&(p[j].first>=p[j-1].second||p[j-1].first>=p[j].second)
Say above is represented as (X||Y)&&(Z||W)
So X is if jth interval start after ith interval
Y is if jth interval end before ith interval

But I am not able to understanf your Z & W conditions

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.