Cod sursa(job #1415709)

Utilizator DenisacheDenis Ehorovici Denisache Data 5 aprilie 2015 21:52:41
Problema Pachete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define pb push_back
#define mp make_pair
using namespace std;
struct point
{
    int x,y;
};
int n;
point firm;
long long sol,D[50005];
vector <point> C[4];
bool cmp(point a,point b)
{
    return a.x<b.x;
}
int solve(vector <point> V)
{
    D[0]=0;
    for (int i=0;i<V.size();i++)
    {
        int st=1,dr=D[0],mid,w=1;
        while (st<=dr)
        {
            mid=(st+dr)>>1;
            if (D[mid]<=V[i].y)
            {
                w=0;
                dr=mid-1;
            }
            else st=mid+1;
        }
        if (w) D[++D[0]]=V[i].y;
        else D[st]=V[i].y;
    }
    return D[0];
}
int main()
{
    freopen("pachete.in","r",stdin);
    freopen("pachete.out","w",stdout);
    scanf("%d",&n);
    scanf("%d %d",&firm.x,&firm.y);
    int x,y;
    point temp;
    for (int i=1;i<=n;i++)
    {
        scanf("%d %d",&x,&y);
        x-=firm.x; y-=firm.y;
        if (x>0 && y>0)
        {
            temp.x=x; temp.y=y;
            C[0].pb(temp);
        }
        if (x<0 && y>0)
        {
            temp.x=-x; temp.y=y;
            C[1].pb(temp);
        }
        if (x<0 && y<0)
        {
            temp.x=-x; temp.y=-y;
            C[2].pb(temp);
        }
        if (x>0 && y<0)
        {
            temp.x=x; temp.y=-y;
            C[3].pb(temp);
        }
    }
    for (int i=0;i<4;i++)
    {
        sort(C[i].begin(),C[i].end(),cmp);
        sol+=solve(C[i]);
    }
    printf("%lld",sol);
    return 0;
}