# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
969384 |
2024-04-25T05:22:05 Z |
vjudge1 |
Cities (BOI16_cities) |
C++17 |
|
21 ms |
5480 KB |
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
const int mxN = 2e5+5;
int n, x, arr[mxN];
pii lis[mxN], inlis[mxN];
int last[mxN];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> x;
vector<int> temp;
for(int i = 1; i <= n; ++i) {
cin >> arr[i];
auto itr = lower_bound(temp.begin(), temp.end(), arr[i]);
if(itr == temp.end())
temp.emplace_back(arr[i]);
else
*itr = arr[i];
lis[i] = {temp[temp.size()-1], temp.size()};
}
temp.clear();
for(int i = n; i >= 1; --i) {
auto itr = lower_bound(temp.begin(), temp.end(), -arr[i]);
if(itr == temp.end())
temp.emplace_back(-arr[i]);
else
*itr = -arr[i];
inlis[i] = {-temp[temp.size()-1], temp.size()};
// cout << inlis[i].first << ' ' << inlis[i].second << '\n';
}
// int ans = 0;
int ans = lis[n].second;
for(int i = 1; i < n; ++i) {
pii t = {lis[i].first - x + 1, 0};
int j = lower_bound(inlis+i+1, inlis+n, t) - inlis;
int sum = lis[i].second + inlis[j].second;
if(t.first > inlis[j].first) continue;
if(sum > ans) {
ans = sum;
// cout << i << ' ' << j << '\n';
// cout << t.first << ' ';
}
}
cout << ans;
}
/*
8 7
7 3 5 12 -2 7 3 4
4 1
-9 -8 -7 -10
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
5468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
5480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
5468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |