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;
int main() {
int n, x;
cin >> n >> x;
int t[n + 1];
for(int i = 1; i <= n; ++i) {
cin >> t[i];
}
// find prefix lis/suffix lis, nanti cari yg max di mana
// suffix lis -> lds dr belakang
// prefix lis -> lis dr depan
int pref[n + 1], suff[n + 2];
pref[0] = 0, suff[n + 1] = 0;
set<int> s;
for(int i = 1; i <= n; ++i) {
if(s.lower_bound(t[i]) != s.end()) {
s.erase(s.lower_bound(t[i]));
s.insert(t[i]);
}
else {
s.insert(t[i]);
}
pref[i] = s.size();
}
for(int i = 1; i <= n; ++i) {
t[i] = -t[i];
}
for(int i = n; i >= 1; --i) {
if(s.lower_bound(t[i]) != s.end()) {
s.erase(s.lower_bound(t[i]));
s.insert(t[i]);
}
else
s.insert(t[i]);
suff[i] = s.size();
}
int out = 0;
for(int i = 1; i <= n; ++i)
out = max(out, pref[i] + suff[i + 1]);
cout << out << 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... |