Cod sursa(job #1525752)

Utilizator Alexa2001Alexa Tudose Alexa2001 Data 15 noiembrie 2015 15:29:56
Problema Pachete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

vector<pair<int,int> > V[4];
int nr,x,y,ox,oy,n,i;

inline void Solve(int z)
{
    if(V[z].empty()) return;
    sort(V[z].begin(),V[z].end());

    set<int> MySet;
    set<int> :: iterator it;
    MySet.clear();
    MySet.insert(V[z][0].second);

    for(int i=1;i<V[z].size();++i)
    {
        it=MySet.upper_bound(V[z][i].second);

        if(it!=MySet.begin()) MySet.erase(--it);
        MySet.insert(V[z][i].second);
    }
    nr+=MySet.size();
}

int main()
{
    freopen("pachete.in","r",stdin);
    freopen("pachete.out","w",stdout);

    scanf("%d%d%d",&n,&ox,&oy);
    for(i=1;i<=n;++i)
    {
         scanf("%d%d",&x,&y);
         x-=ox;y-=oy;

         if(x>0 && y>0) V[0].push_back({x,y});
    else if(x<0 && y>0) V[1].push_back({-x,y});
    else if(x>0 && y<0) V[2].push_back({x,-y});
    else if(x<0 && y<0) V[3].push_back({-x,-y});
    }
    Solve(0);
    Solve(1);
    Solve(2);
    Solve(3);

    printf("%d\n",nr);

    return 0;
}