이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
void solve()
{
ll n, x;
cin >> n >> x;
ll a[n];
for (ll &i : a)
cin >> i;
ll dp[n], dp2[n];
pair<ll, ll> dp1[n];
for (ll i = 0; i < n; i++)
{
dp[i] = 1;
dp1[i] = make_pair(1, x);
dp2[i] = -1e18;
for (ll j = 0; j < i; j++)
{
if (a[j] < a[i])
dp[i] = max(dp[i], dp[j] + 1);
if (a[j] < a[i])
dp1[i] = max(dp1[i], make_pair(dp1[j].first + 1, dp1[j].second));
if (a[j] - dp1[j].second < a[i])
dp2[i] = max(dp2[i], dp1[j].first + 1);
if (a[j] < a[i]) dp2[i] = max(dp2[i], dp2[j] + 1);
if (min(x, max(-x, a[j] - a[i] + 1)) + a[i] > a[j])
dp1[i] = max(dp1[i], make_pair(dp[j] + 1, -min(x, max(-x, a[j] - a[i] + 1))));
}
}
ll ans = 0;
for (ll i = 0; i < n; i++)
ans = max({ans, dp[i], dp2[i], dp1[i].first});
cout << ans << endl;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t = 1;
// precomp();
// cin >> t;
for (ll i = 1; i <= t; i++)
solve();
cerr << "\nTime elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n";
}
# | 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... |