题解:AT_abc457_g [ABC457G] Catch All Apples
传送门
题解
对于两个苹果
一个机器人能同时接到它们当且仅当存在一条速度小于等于
故有
这个式子。
令
变为切比雪夫距离。
变为
这个式子。
假设有
也就是说:同一个机器人能回收的苹果,在
根据 Dilworth 定理:最小链覆盖等于最大反链的大小等于最长严格下降子序列的长度。
AC code:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=3e5+5;
int n;
struct Node{
int x,y;
bool operator<(const Node &nd)const{
return x==nd.x?y<nd.y:x>nd.x;
}
};
Node a[N];
signed main(){
//HAPPY!
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
int x,y;
cin>>x>>y;
a[i]={y-x,y+x};
}
sort(a+1,a+n+1);
vector<int> res;
for(int i=1;i<=n;i++){
int val=-a[i].y;
auto it=lower_bound(res.begin(),res.end(),val);
if(it==res.end()){
res.push_back(val);
}
else{
*it=val;
}
}
cout<<res.size()<<"\n";
return 0;
}