# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
916341 | KactusJack | Global Warming (CEOI18_glo) | C++17 | 35 ms | 2812 KiB |
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>
#define ll long long
#define F first
#define S second
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, x;
cin >> n >> x;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
vector<int> prefix(n), suffix(n), dp;
for(int i = 0; i < n; i++){
a[i] -= x;
int j = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
if(j == dp.size()){
dp.push_back(a[i]);
}
else{
dp[j] = a[i];
}
prefix[i] = dp.size();
}
for(int i = 0; i < n; i++){
a[i] *= -1;
}
dp.clear();
for(int i = n-1; i >= 0; i--){
a[i] -= x;
int j = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
if(j == dp.size()){
dp.push_back(a[i]);
}
else{
dp[j] = a[i];
}
suffix[i] = dp.size();
}
int ans = 0;
for(int i = 0; i < n; i++){
ans = max(ans, prefix[i] + suffix[i] - 1);
}
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
# | 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... |