#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
const int N = 500 + 10;
const int inf = 2e9;
const int mod = 998244353;
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,x,res = 0;
cin >> n >> x;
vector<int>a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
a[i] -= x;
}
vector<pair<int,int>>pref(n);
vector<int>v;
for(int i = 0; i < n; i++) {
if(v.empty() || v.back() < a[i]) {
v.pb(a[i]);
}else {
int lb = lower_bound(v.begin(),v.end(),a[i]) - v.begin();
v[lb] = a[i];
}
pref[i] = {v.back(),v.size()};
}
res = pref[n - 1].S;
for(int i = 0; i < n; i++) {
a[i] += x;
a[i] *= -1;
}
vector<int>vec;
for(int i = n - 1; i > 0; i--) {
if(vec.empty() || vec.back() < a[i]) {
vec.pb(a[i]);
}else {
int lb = lower_bound(vec.begin(),vec.end(),a[i]) - vec.begin();
vec[lb] = a[i];
}
int l = 0,r = i - 1,ans = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(pref[mid].F < -vec.back()) {
ans = mid;
l = mid + 1;
}else {
r = mid - 1;
}
}
res = max(res,(int)vec.size() + (ans != -1 ? pref[ans].S : 0));
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
416 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
416 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
416 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
4956 KB |
Output is correct |
2 |
Correct |
40 ms |
4956 KB |
Output is correct |
3 |
Correct |
39 ms |
5156 KB |
Output is correct |
4 |
Correct |
45 ms |
5416 KB |
Output is correct |
5 |
Correct |
20 ms |
7356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1628 KB |
Output is correct |
2 |
Correct |
9 ms |
1628 KB |
Output is correct |
3 |
Correct |
9 ms |
1652 KB |
Output is correct |
4 |
Correct |
5 ms |
2140 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
2528 KB |
Output is correct |
7 |
Correct |
9 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
2832 KB |
Output is correct |
2 |
Correct |
19 ms |
2788 KB |
Output is correct |
3 |
Correct |
39 ms |
6996 KB |
Output is correct |
4 |
Correct |
21 ms |
8408 KB |
Output is correct |
5 |
Correct |
11 ms |
4316 KB |
Output is correct |
6 |
Correct |
18 ms |
8408 KB |
Output is correct |
7 |
Correct |
21 ms |
8920 KB |
Output is correct |
8 |
Correct |
17 ms |
3672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
416 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |