I was trying to solve this question Problem using the concept that answer would be the longest non increasing sequence but it fails on some test cases idk why? Please help me sort it out. Here is my Soln: ~~~~~
#include <bits/stdc++.h>
using namespace std;
int find_lis(vector<int> a) {
vector<int> dp;
for (int i : a) {
int pos = upper_bound(dp.begin(), dp.end(), i)- ``dp.begin();
if (pos == dp.size()) {
// we can have a new, longer increasing subsequence!
dp.push_back(i);
} else {
// oh ok, at least we can make the ending element smaller
dp[pos] = i;
}
}
return dp.size();
}
int main(){
ifstream fin("cowjog.in");
ofstream fout("cowjog.out");
int n,t;fin>>n>>t;
vector<vector<int>> v(n, vector<int>(2));
for(int i=0;i<n;i++) { int x,y;fin>>x>>y; v[i][0]=x, v[i][1]=y; }
sort(v.begin(), v.end());
vector<int> vec(n);
for(int i=0;i<n;i++){
vec[i]=(v[i][0]+t*v[i][1]);
}
reverse(vec.begin(), vec.end());
fout<<find_lis(vec)<<endl;
}
~~~~~