#include <bits/stdc++.h>
using namespace std;
int sir[200001] , stiva[200001] , termen[200001] , maxim;
inline void GetMax (const int lungime , const int limita)
{
for (int indice = lungime ; indice ; indice--)
{
int stanga = 1 , dreapta = stiva[0];
while (stanga <= dreapta)
{
const int mijloc = (stanga + dreapta) >> 1;
if (stiva[mijloc] > sir[indice]) { stanga = mijloc + 1; }
else { dreapta = mijloc - 1; }
}
if (stanga > stiva[0])
{ stiva[0]++; }
stiva[stanga] = sir[indice];
termen[indice] = stanga;
}
stiva[0] = 0;
for (int indice = 1 ; indice <= lungime ; indice++)
{
int stanga = 1 , dreapta = stiva[0];
while (stanga <= dreapta)
{
const int mijloc = (stanga + dreapta) >> 1;
if (stiva[mijloc] <= sir[indice] + limita) { stanga = mijloc + 1; }
else { dreapta = mijloc - 1; }
}
maxim = max(maxim , dreapta + termen[indice]);
stanga = 1 , dreapta = stiva[0];
while (stanga <= dreapta)
{
const int mijloc = (stanga + dreapta) >> 1;
if (stiva[mijloc] < sir[indice]) { stanga = mijloc + 1; }
else { dreapta = mijloc - 1; }
}
if (stanga > stiva[0])
{ stiva[0]++; }
stiva[stanga] = sir[indice];
}
stiva[0] = 0;
}
int main ()
{
ios :: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int lungime , limita;
cin >> lungime >> limita;
for (int indice = 1 ; indice <= lungime ; indice++)
{ cin >> sir[indice]; }
limita--;
GetMax(lungime , limita);
for (int stanga = 1 , dreapta = lungime ; stanga < dreapta ; stanga++ , dreapta--)
{
swap(sir[stanga] , sir[dreapta]);
sir[dreapta] *= -1;
sir[stanga] *= -1;
}
if (lungime & 1)
{ sir[(lungime + 1) >> 1] *= -1; }
GetMax(lungime , limita);
cout << maxim;
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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |