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>
#define fu(i, a, b) for(int i = (a); i <= (b); i++)
#define fd(i, a, b) for(int i = (a); i >= (b); i--)
#define ll long long
using namespace std;
const int N = 5e3 + 5;
const int MAXA = 5005;
const int INF = 1e9 + 5;
int n;
int lim;
int a[N];
struct Segment
{
vector<int> nodes;
void init(int n)
{
nodes.resize(4 * n + 5, INF);
}
void update(int id, int l, int r, int u, int v, int val)
{
if(v < l || u > r) return;
if(l == r) {
nodes[id] = val;
return;
}
int mid = (l + r) / 2;
update(id * 2, l, mid, u, v, val);
update(id * 2 + 1, mid + 1, r, u, v, val);
nodes[id] = min(nodes[id * 2], nodes[id * 2 + 1]);
}
int get(int id, int l, int r, int u, int v)
{
if(v < l || u > r) return INF;
if(u <= l && r <= v) return nodes[id];
int mid = (l + r) / 2;
return min(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
};
Segment f;
int dp[N];
vector<int> lis;
int LIS()
{
int maxlen = 0;
int sz = (int)lis.size();
fu(i, 0, sz - 1)
{
int x = upper_bound(dp, dp + maxlen, lis[i]) - dp;
if(x == maxlen) {
dp[maxlen] = lis[i];
maxlen++;
}
else {
dp[x] = lis[i];
}
}
return maxlen;
}
void solve()
{
fu(i, 1, n)
{
if(i * lim >= a[i]) {
lis.push_back(i * lim - a[i]);
}
}
cout << n - LIS();
}
void read()
{
cin >> n >> lim;
fu(i, 1, n) cin >> a[i];
solve();
}
int main()
{
// freopen("tester.inp","r",stdin);
// freopen("tester.out","w",stdout);
ios_base::sync_with_stdio(false);cin.tie(0);
read();
}
# | 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... |