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;
#define LIFESUCKS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define ar array
#include<cstdio>
#define vt vector
#include<fstream>
ifstream fin("snakes.in");
ofstream fout("snakes.out");
#include<fstream>
#define pb push_back
#define dq deque
#define all(c) (c).begin(), (c).end()
//#define length(x) (int)(x).size()
#define fi first
#define se second
#define vt vector
int main()
{
LIFESUCKS;
ll n, m; cin >> n >> m;
ll a[n];
for(int i = 0; i < n; i++)cin >> a[i];
ll dp[n];
ll ans =0;
int cr = -1;
for(int i = n - 1; i >= 0; i--){
if(a[i] <= m * (i + 1)){
cr = i;
//cout << i << " ";
//cout << cr << " ";
dp[0] = a[i] - m * (i + 1);
break;
}
}
if(cr == -1){
cout << n;
return(0);
}
//cout << cr << " ";
for(int i = cr - 1; i >= 0; i--){
if(a[i] <= m * (i + 1)){
ll curr = a[i] - m * (i + 1);
ll id = upper_bound(dp, dp + ans + 1, curr) - dp;
ans = max(ans, id);
dp[id] = curr;
}
}
cout << n - (ans + 1);
return 0;
}
# | 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... |