This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
int __i__, __j__;
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
const int NN = 2e5+2, mod = 1e9 + 7;
int n, m;
vi dp, a;
bool comp(const int &x, const int &y){
return a[y] - a[x] <= (y-x)*m;
}
int lis(vi a){
vi dp;
for(int i=0;i<=n;i++){
int pos = lower_bound(dp.begin(), dp.end(), i, comp) - dp.begin();
if(pos == dp.size()){
dp.push_back(i);
}
else if(pos != 0){
dp[pos] = i;
}
//printArr(dp, dp.size()); cout << "\n";
}
return dp.size();
}
int main()
{
cin >> n >> m; a.resize(n+1);
for(int i=1;i<=n;i++)cin >> a[i];
cout << n+1 - lis(a) << endl;
//cout << comp(a[2], a[3]);
return 0;
}
Compilation message (stderr)
triusis.cpp: In function 'int lis(vi)':
triusis.cpp:30:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | if(pos == dp.size()){
| ~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |