Activity Selection Problem

when I initialize the vector by v(n); it will give wrong answer, why!!!

It gives wrong answer because line 15 already initializes a vector of size n. And push_back statement always pushes new values at the end of the vector.
For example -
vector v(5);
This statement initializes a vector of size 5, with all values 0 initially - 0 0 0 0 0
Now, if we do v.push_back(1), the vector will become - 0 0 0 0 0 1

1 Like