Pagini recente » Cod sursa (job #847343) | Cod sursa (job #1848907) | Cod sursa (job #942074) | Cod sursa (job #1568201) | Cod sursa (job #2163533)
#include <bits/stdc++.h>
using namespace std;
ifstream in("tribute.in");
ofstream out("tribute.out");
const int COORD_MAX = 50005, INF = 2e9;
int n, dx, dy, x, y;
int ansX, ansY;
int stX[COORD_MAX + 2], drX[COORD_MAX + 2];
int stY[COORD_MAX + 2], drY[COORD_MAX + 2];
void calcSt()
{
for(int i = 1; i <= COORD_MAX; i++)
{
stX[i] += stX[i - 1];
stY[i] += stY[i - 1];
}
}
void calcDr()
{
for(int i = COORD_MAX - 1; i >= 0; i--)
{
drX[i] += drX[i + 1];
drY[i] += drY[i + 1];
}
}
int main()
{
in >> n >> dx >> dy;
while(n--)
{
in >> x >> y;
stX[x + 1]++; drX[x - 1]++;
stY[y + 1]++; drY[y - 1]++;
}
calcSt();
calcSt();
calcDr();
calcDr();
ansX = ansY = INF;
for(x = 0; x <= COORD_MAX; x++)
ansX = min(ansX, stX[x] + drX[x + dx]);
for(y = 0; y <= COORD_MAX; y++)
ansY = min(ansY, stY[y] + drY[y + dy]);
out << ansX + ansY << '\n';
return 0;
}