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;
typedef pair<int,int> pii;
const int MAXN=1e6+5;
int MAX,a[MAXN],T[MAXN],A[MAXN],bit[MAXN];
pii arr[MAXN];
int query(int x){
int ret=0;
for(int i=x;i>0;i-=(i&-i)){
ret=max(ret,bit[i]);
}
return ret;
}
void update(int x,int v){
for(int i=x;i<=MAX;i+=(i&(-i))){
bit[i]=max(bit[i],v);
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,m;
cin >> n >> m;
for(int i=1;i<=m;i++)cin >> T[i];
for(int i=1;i<=m;i++)cin >> A[i];
for(int i=1;i<=m;i++)arr[i]={A[i]+T[i],-(A[i]-T[i])};
sort(arr+1,arr+m+1);
vector<pii> v;
for(int i=1;i<=m;i++){
a[i]=-arr[i].second;
v.push_back({a[i],i});
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++){
if(i==0 || v[i].first!=v[i-1].first)MAX++;
a[v[i].second]=MAX;
}
int ans=0;
for(int i=1;i<=m;i++){
int dp=query(a[i]-1)+1;
update(a[i],dp);
ans=max(ans,dp);
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
Arcade.cpp: In function 'int main()':
Arcade.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
# | 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... |