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 "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 2e5+5;
const int INF = 1e9;
int cep[N], sag[N], v[N], dp[N];
int main(){
int n, x; scanf("%d%d", &n, &x);
for(int i = 0; i < n; ++i){
int x; scanf("%d", &x);
v[i] = x;
}
auto reload = [&]() {
for(int i = 0; i < n; ++i)
dp[i] = INF;
};
int answer = 0;
reload();
for(int i = 0; i < n; ++i){
int j = lower_bound(dp, dp+n, v[i])-dp;
dp[j] = v[i], cep[i] = j+1;
}
reload();
for(int i = n-1; i >= 0; --i){
int j = lower_bound(dp, dp+n, -v[i]+x)-dp;
sag[i] = j;
j = lower_bound(dp, dp+n, -v[i])-dp;
dp[j] = -v[i];
}
for(int i = 0; i < n; ++i)
umax(answer, cep[i]+sag[i]);
printf("%d\n", answer);
return 0;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:20:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | int n, x; scanf("%d%d", &n, &x);
| ~~~~~^~~~~~~~~~~~~~~~
glo.cpp:22:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | int x; scanf("%d", &x);
| ~~~~~^~~~~~~~~~
# | 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... |