int lis(vector<int> &a) {
int n = a.size();
const int INF = 1e9 + 1;
vector<int> d(n+1, INF);
d[0] = -INF;
for (int i = 0; i < n; i++) {
int j = upper_bound(d.begin(), d.end(), a[i]) - d.begin();
if (d[j-1] < a[i] && a[i] < d[j])
d[j] = a[i];
}
int ans = 0;
for (int i = 0; i <= n; i++) {
if (d[i] < INF)
ans = i;
}
for(int i = 1;i <= ans; i++){
cout<<d[i]<<" ";
}
return ans;
}
It's easier to try testing in this link :)
LIS
array: 3 4 5 1 2
answer: 3 4 5
your output: 1 2 5