이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
int arr[200001];
int n, x;
vector <int> sup;
int dp[200001];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin>>n>>x;
for (int i=0; i<n; i++)
{
cin>>arr[i];
}
for (int i=0; i<n; i++)
{
auto it = lower_bound(sup.begin(), sup.end(), arr[i]);
if (it == sup.end())
{
sup.pb(arr[i]);
dp[i] = sup.size();
continue;
}
int pos = it - sup.begin();
dp[i] = pos + 1;
sup[pos] = arr[i];
}
sup.clear();
int mx = 0;
for (int i=n-1; i>=0; i--)
{
auto it = lower_bound(sup.begin(), sup.end(), -(arr[i]-x));
int val = (it-sup.begin());
val += dp[i];
mx = max(val, mx);
it = lower_bound(sup.begin(), sup.end(), -(arr[i]));
if (it == sup.end())
{
sup.pb(-arr[i]);
continue;
}
int pos = it - sup.begin();
sup[pos] = -arr[i];
}
cout<<mx;
}
# | 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... |