Pagini recente » Cod sursa (job #242083) | Cod sursa (job #808714) | Cod sursa (job #1346304) | Cod sursa (job #1578280) | Cod sursa (job #1384137)
#include <cstdio>
#include <algorithm>
#include <climits>
#define Nmax 50010
using namespace std;
int n , i , j , a , b , Dx , Dy , Lx , Ly , nrX_st , nrX_dr , nrY_jos , nrY_sus , costX = INT_MAX , costY = INT_MAX;
int X[Nmax] , Y[Nmax] , stX[Nmax] , drX[Nmax] , josY[Nmax] , susY[Nmax];
int main()
{
freopen("tribute.in","r",stdin);
freopen("tribute.out","w",stdout);
for (scanf("%d %d %d", &n, &Dx, &Dy) , i = 1; i <= n; ++i)
{
scanf("%d %d", &a, &b);
X[a]++; Y[b]++;
}
///sume partiale pe vectorii de aparitie
for (i = 0 , j = Nmax; i <= Nmax; ++i , --j)
{
stX[i] = stX[i-1] + nrX_st;
josY[i] = josY[i-1] + nrY_jos;
drX[j] = drX[j+1] + nrX_dr;
susY[j] = susY[j+1] + nrY_sus;
nrX_st += X[i] , nrY_jos += Y[i] , nrX_dr += X[j] , nrY_sus += Y[j];
}
///line sweep pe Ox
for (Lx = 0; Lx <= Nmax - Dx; ++Lx)
costX = min(costX , stX[Lx] + drX[Lx+Dx]);
///line sweep pe Oy
for (Ly = 0; Ly <= Nmax - Dy; ++Ly)
costY = min(costY , josY[Ly] + susY[Ly+Dy]);
printf("%d\n", costX + costY);
return 0;
}