Pagini recente » Cod sursa (job #1675617) | Cod sursa (job #2301534) | Cod sursa (job #404892) | Cod sursa (job #486240) | Cod sursa (job #2260797)
#include <fstream>
using namespace std;
ifstream in("tribute.in");
ofstream out("tribute.out");
const int N=50000;
long long vfx[N+1],vfy[N+1];
int main()
{
int n,x,y,i,a,b;
long long min1=3e9,min2=3e9,scor=0;
in>>n>>x>>y;
for(i=1; i<=n; ++i)
{
in>>a>>b;
vfx[a]++;
vfy[b]++;
}
int catest=0,catedr=0,cate=0;
for(i=0; i<x; i++)
cate+=vfx[i];
for(; i<=N; i++)
{
scor+=(long long)vfx[i]*(i-x+1);
catedr+=vfx[i];
}
min1=scor;
for(i=1; i<=N-x+1; i++)
{
catest+=vfx[i-1];
cate+=vfx[x+i-1];
scor+=catest;
scor-=catedr;
if(scor<min1)
min1=scor;
catedr-=vfx[x+i-1];
}
catest=0;
catedr=0;
cate=0;
scor=0;
for(i=0; i<y; i++)
cate+=vfy[i];
for(; i<=N; i++)
{
scor+=(long long)vfy[i]*(i-y+1);
catedr+=vfy[i];
}
min2=scor;
for(i=1; i<=N-y+1; i++)
{
catest+=vfy[i-1];
cate+=vfy[y+i-1];
scor+=catest;
scor-=catedr;
if(scor<min2)
min2=scor;
catedr-=vfy[y+i-1];
}
out<<min1+min2;
return 0;
}