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 <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <climits>
#include <vector>
#include <queue>
#include <utility>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <string>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
ll n, x;
cin >> n >> x;
ll t[n];
for (int i = 0; i < n; i++)
cin >> t[i];
vi dp(n, INT_MAX), pref(n);
ll res = 0;
for (int i = 0; i < n; i++){
ll j = upper_bound(dp.begin(), dp.end(), t[i]) - dp.begin();
dp[j] = t[i];
pref[i] = j + 1;
res = max(res, j + 1);
}
dp.assign(n, INT_MAX);
for (int i = n - 1; i >= 0; i--){
int j = upper_bound(dp.begin(), dp.end(), -t[i] + x) - dp.begin();
res = max(res, pref[i] + j - 1);
j = upper_bound(dp.begin(), dp.end(), -t[i]) - dp.begin();
dp[j] = -t[i];
}
cout << res << endl;
}
# | 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... |