# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1254605 | snairs | Rabbit Carrot (LMIO19_triusis) | C++20 | 1 ms | 328 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0);
if ((int)name.size()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
int poles(vector<ll> const& a, ll m)
{
int n = a.size();
const int INF = 1e9;
vector<ll> d(n+1, INF);
d[0] = -INF;
for (int i = 0; i < n; i++)
{
int l = upper_bound(d.begin(), d.end(), a[i]-m) - d.begin();
if (d[l-1] <= a[i] && a[i] <= d[l])
d[l] = a[i];
}
int ans = 0;
for (int l = 0; l <= n; l++)
{
if (d[l] < INF) ans = l;
}
return ans;
}
int main() {
setIO();
ll n,m;
cin >> n >> m;
vector <ll> height(n+1);
height[0]=0;
for(int i=0;i<n;i++) cin >> height[i+1];
cout << poles(height,m)-1;
}
Compilation message (stderr)
# | 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... |