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 <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
typedef long long llong;
const int MAXN = 300000 + 10;
const int INF = 1e9;
int n, d;
int a[MAXN];
int dp[MAXN];
int perm[MAXN];
bool bigger[MAXN];
void solve()
{
std::iota(perm + 1, perm + 1 + n, 1);
std::sort(perm + 1, perm + 1 + n, [&](int x, int y)
{
return a[x] > a[y] || (a[x] == a[y] && x < y);
});
int res = 0;
for (int i = 1 ; i <= n ; ++i)
{
int len = 0;
for (int j = perm[i] + 1 ; j <= n ; ++j)
{
len += bigger[j];
if (len > d)
{
break;
}
if (bigger[j])
{
dp[perm[i]] = std::max(dp[perm[i]], dp[j]);
} else
{
len = 0;
}
}
dp[perm[i]]++;
bigger[perm[i]] = true;
res = std::max(res, dp[perm[i]]);
}
std::cout << res << '\n';
}
void input()
{
std::cin >> n >> d;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i];
}
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIOI();
input();
solve();
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... |