Pagini recente » Cod sursa (job #2311659) | Cod sursa (job #827926) | Cod sursa (job #489685) | Cod sursa (job #43834) | Cod sursa (job #600947)
Cod sursa(job #600947)
#include <fstream>
using namespace std;
const int N=50005;
int X[2*N],Y[2*N],dX,dY,st,dr,n;
ifstream in("tribute.in");
ofstream out("tribute.out");
int det(int v[],int D)
{
int i,M,dist=0;
for (i=D;i<N;i++)
dist+=v[i]*(i-D);
M=dist;
for (i=1;i<N;i++)
v[i]+=v[i-1];
for (i=1;i+D<N;i++)
{
dist+=v[i-1];
dist-=n-v[i+D-1];
M=min(dist,M);
}
return M;
}
int main()
{
int i,x,y;
in>>n>>dX>>dY;
for (i=1;i<=n;i++)
{
in>>x>>y;
X[x]++;
Y[y]++;
}
out<<det(X,dX)+det(Y,dY)<<"\n";
return 0;
}