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 n, x, HI;
int binarySearch(int x, vector<int>& V, int d){
int hi = V.size()-1;
int lo = 0;
while(hi >= lo){
int mid = lo + (hi - lo)/2;
if((V[mid]-d) < x) lo = mid+1;
else hi = mid-1;
}
return lo;
}
int main(){
cin >> n >> x;
vector<int> nums(n);
for(int i = 0; i < n; ++i) cin >> nums[i];
vector<vector<int>> dp(2, vector<int>(1));
dp[0][0] = nums[0];
dp[1][0] = nums[0];
for(int i = 1; i < nums.size(); ++i){
int pos = binarySearch(nums[i], dp[0], 0);
if(pos == dp[0].size()){
dp[0].push_back(nums[i]);
}
else dp[0][pos] = nums[i];
//cout << i <<" " << pos << endl;
pos = binarySearch(nums[i], dp[1], 0);
if(pos == dp[1].size()){
dp[1].push_back(nums[i]);
}
else dp[1][pos] = nums[i];
pos = binarySearch(nums[i], dp[0], x);
if(pos == dp[1].size()){
dp[1].push_back(nums[i]);
}
else dp[1][pos] = min(dp[1][pos],nums[i]);
}
cout << max(dp[0].size(), dp[1].size()) << endl;
return 0;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 1; i < nums.size(); ++i){
| ~~^~~~~~~~~~~~~
glo.cpp:29:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | if(pos == dp[0].size()){
| ~~~~^~~~~~~~~~~~~~~
glo.cpp:36:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | if(pos == dp[1].size()){
| ~~~~^~~~~~~~~~~~~~~
glo.cpp:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | if(pos == dp[1].size()){
| ~~~~^~~~~~~~~~~~~~~
# | 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... |