Pagini recente » Cod sursa (job #2108012) | Cod sursa (job #933201) | Cod sursa (job #2387383) | Cod sursa (job #285034) | Cod sursa (job #2465300)
#include <fstream>
using namespace std;
ifstream fin("tribute.in");
ofstream fout("tribute.out");
int n, dx, dy;
int cntx[50001], cnty[50001];
long long Solve(int d, int *cnt)
{
long long l=0, r=0;
long long s=0, ans=6e9;
for (int i=50000; i>=d; --i)
{
r+=cnt[i];
s+=r;
}
for(int i=0; i<50001-d; ++i)
{
s-=r;
r-=cnt[i+d];
ans=min(ans, s);
l+=cnt[i];
s+=l;
}
return ans;
}
int main()
{
fin>>n>>dx>>dy;
for(int i=0;i<n;++i)
{
int x, y;
fin>>x>>y;
++cntx[x];
++cnty[y];
}
fout<<Solve(dx, cntx)+Solve(dy, cnty)<<"\n";
return 0;
}