#include <bits/stdc++.h>
#define int long long
#define vi vector<int>
#define ii pair<int, int>
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define P 31
#define mod 1'000'000'007
#define inf 1'000'000'000'000
#define pb push_back
#define str string
#define sz(x) (x).size()
#define vvi vector<vi>
#define fun function
#define oopt cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false);
#define file freopen("problemname.in", "r", stdin); freopen("pr.out", "w", stdout);
#define dbg(v) cout << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;
using namespace std;
template <class T, int SZ> using arr = array<T, SZ>;
void solve()
{
int n, x;
cin >> n >> x;
vi a(n);
for (int&v:a)
cin >> v;
vi lis;
vi dis(n);
vi t;
for (int i = n-1; i >= 0; i--)
{
int tr = -a[i];
if (t.empty() || tr > t.back())
t.pb(tr);
else
{
int ix = lower_bound(all(t), tr)-t.begin();
t[ix] = tr;
}
dis[i] = t.size();
}
int rez = dis[0];
for (int i = 0; i < n; i++)
{
if (lis.size() && lis.back() < a[i]+x)
{
rez = max(rez, (int)lis.size()+dis[i]);
}
// cout << i << " " << lis.size() << " " << dis[i] << "\n";
if (lis.empty() || a[i] > lis.back())
lis.pb(a[i]);
else
{
int ix = lower_bound(all(lis), a[i])-lis.begin();
lis[ix] = a[i];
}
}
cout << rez << "\n";
}
signed main()
{
oopt;
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
5456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
1616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2896 KB |
Output is correct |
2 |
Correct |
17 ms |
2896 KB |
Output is correct |
3 |
Correct |
34 ms |
5452 KB |
Output is correct |
4 |
Correct |
18 ms |
6976 KB |
Output is correct |
5 |
Correct |
9 ms |
3536 KB |
Output is correct |
6 |
Correct |
17 ms |
6920 KB |
Output is correct |
7 |
Correct |
19 ms |
7560 KB |
Output is correct |
8 |
Correct |
15 ms |
2896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |