Cod sursa(job #350500)

Utilizator hendrikHendrik Lai hendrik Data 24 septembrie 2009 15:08:18
Problema Ograzi Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <iostream>
#include <vector>
using namespace std;

#define pb push_back
#define Sz size()
#define mp make_pair
typedef pair<int,int>pii;
int n,m,h,w,a,b,ans,x1,y1,x2,y2;
vector<pii>v;

void open(){
    freopen("ograzi.in","r",stdin);
    freopen("ograzi.out","w",stdout);
}

int main(){
    open();
    scanf("%d%d%d%d",&n,&m,&h,&w);
    for (int i=0;i<n;i++){
        scanf("%d %d",&a,&b);
        v.pb(mp(a,b));
    }
    sort(v.begin(),v.end());
    ans=0;
    for (int i=0;i<m;i++){
        scanf("%d %d",&a,&b);
        int lo=lower_bound(v.begin(),v.end(),mp(a,b))-v.begin();
        if (lo==0){
            x1=v[lo].first;
            y1=v[lo].second;
            x2=x1+h;
            y2=y1+w;
            if (a>=x1 && b>=y1 && a<=x2 && b<=y2) ans++;
        }
        else {
            x1=v[lo].first;
            y1=v[lo].second;
            x2=x1+h;
            y2=y1+w;
            if (a>=x1 && b>=y1 && a<=x2 && b<=y2) ans++;
            else {
                lo--;
                x1=v[lo].first;
                y1=v[lo].second;
                x2=x1+h;
                y2=y1+w;
                if (a>=x1 && b>=y1 && a<=x2 && b<=y2) ans++;
            }
        }
    }
    printf("%d\n",ans);
    //system("pause");
    return 0;
}