이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define debug(x) cerr<<#x<<" :"<<x<<"\n"
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
#define int long long
typedef long long ll;
typedef long double ld;
const int maxn = 5e5 + 7;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const int mlog = 20;
const int SQ = 400;
int a[maxn];
int L[maxn], R[maxn];
int dp[maxn], pd[maxn];
int32_t main()
{
FAST;
int n, x;
cin >> n >> x;
for(int i = 1; i <= n; i++)
cin >> a[i], dp[i] = pd[i] = +INF;
for(int i = 1; i <= n; i++)
{
int pos = lower_bound(dp + 1, dp + 1 + n, a[i]) - dp;
L[i] = pos + 1;
dp[pos] = a[i];
}
for(int i = n; i > 0; i--)
{
int pos = lower_bound(pd + 1, pd + 1 + n, -a[i] + x) - pd;
R[i] = pos + 1;
int npos = lower_bound(pd + 1,pd + 1 + n, -a[i]) - pd;
dp[npos] = -a[i];
}
int ans = 0;
for(int i = 1; i <= n; i++) ans = max(ans, R[i] + L[i] - 1);
cout << ans << "\n";
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... |