이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, x; cin >> n >> x;
vector <int> a(n);
for ( auto &u: a ) cin >> u;
const int inf = 1e12;
vector <int> p(n + 1, -inf), r(n);
for ( int i = n - 1; i >= 0; i-- ){
int it = upper_bound(all(p), a[i]) - p.begin() - 1;
p[it] = a[i];
if ( i > 0 ){
r[i - 1] = p.end() - upper_bound(all(p), a[i - 1] - x);
}
}
int opt = p.end() - upper_bound(all(p), -inf + 1);
p.assign(n + 1, inf);
for ( int i = 0; i + 1 < n; i++ ){
int it = lower_bound(all(p), a[i]) - p.begin();
p[it] = a[i];
chmax(opt, r[i] + it + 1);
}
cout << opt;
cout << '\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... |