Cod sursa(job #2496148)

Utilizator miha5092mihai mitrea miha5092 Data 20 noiembrie 2019 11:58:11
Problema Ograzi Scor 0
Compilator cpp-64 Status done
Runda casiaiziscanudaisimulareprimaora Marime 1.83 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream in("ograzi.in");
ofstream out("ograzi.out");

struct coordonate
{
    int x;
    int y;
};

int n, m, w, h;
coordonate ograzi[50005], oi[100005];

void citire()
{
    in >> n >> m >> w >> h ;
    int x, y;
    for(int i=1; i<=n; i++)
    {
        in >> x >> y ;
        ograzi[i].x = x ;
        ograzi[i].y = y ;
    }
    for(int i=1; i<=m; i++)
    {
        in >> x >> y ;
        oi[i].x = x ;
        oi[i].y = y ;
    }
}

bool cmp(coordonate a, coordonate b)
{
    if(a.x < b.x)
        return true;
    else if(a.x > b.x)
        return false;
    else
    {
        if(a.y < b.y)
            return true;
        else
            return false;
    }
}

int main()
{
    int ans = 0 ;
    citire();
    sort(ograzi+1, ograzi+n+1, cmp);
    sort(oi+1, oi+m+1, cmp);
    int cnt_oi=1, cnt_ogr=1;
    while(cnt_oi <= m)
    {
        if(oi[cnt_oi].x < ograzi[cnt_ogr].x && oi[cnt_oi].y < ograzi[cnt_ogr].y)
        {
            ans++;
            cnt_oi++;
        }
        else if(cnt_ogr == m && ( oi[cnt_oi].x > ograzi[cnt_ogr].x+w || oi[cnt_oi].y > ograzi[cnt_ogr].y+h ))
        {
            ans++;
            cnt_oi++;
        }
        else
        {
            while( (oi[cnt_oi].x > ograzi[cnt_ogr].x+w || oi[cnt_oi].y > ograzi[cnt_ogr].y+h) && cnt_ogr < n)
            {
                cnt_ogr++;
            }
            if(oi[cnt_oi].x >= ograzi[cnt_ogr].x && oi[cnt_oi].x <= ograzi[cnt_ogr].x+w && oi[cnt_oi].y >= ograzi[cnt_ogr].y && oi[cnt_oi].y <= ograzi[cnt_ogr].y+h)
            {
                cnt_oi++;
            }
            else
                {
                    cnt_oi++;
                    ans++;
                }
            }
    }
    out << ans ;
    return 0;
}