Gym-100820 Racing Gems(二维LIS)

来源:互联网 发布:09和冷冷的故事 知乎 编辑:程序博客网 时间:2024/06/09 17:23

传送门:http://codeforces.com/gym/100820/attachments

#include<bits/stdc++.h>using namespace std;typedef long long LL;const int MX = 1e5 + 5;struct node{    LL a,b;}p[MX];bool cmp(node p1,node p2){    if(p1.a!=p2.a) return p1.a<p2.a;    return p1.b<p2.b;}LL d[MX];int main(){    int n,r,w,h;    //freopen("in.txt","r",stdin);    while(~scanf("%d%d%d%d",&n,&r,&w,&h)){        for(int i=1;i<=n;i++){            LL x,y;            scanf("%I64d%I64d",&x,&y);            p[i].a=r*(w-x)+y;            p[i].b=r*x+y;        }        sort(p+1,p+n+1,cmp);        memset(d,0x3f,sizeof(d));        int len=0;        for(int i=1;i<=n;i++){            int pos=upper_bound(d+1,d+n+1,p[i].b)-d;            d[pos]=p[i].b;            len=max(len,pos);        }        printf("%d\n",len);    }    return 0;}