Cod sursa(job #647576)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 11 decembrie 2011 17:05:27
Problema Tribute Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 50005
#define ui unsigned int
ui x[N],y[N],n,dx,dy,i;
      
ui h(ui x[N],ui dx)
{ui k=0,j=0,m=(1<<31),z[N]={0},p[N],r[N];
sort(x+1,x+n+1);
if(dx>=x[n]-x[1])
      return 0;
for(i=1;i<=n;i++)
      z[x[i]+1]++;
z[x[1]]=p[x[1]]=r[x[1]]=0;
for(i=x[1];i<=x[n]-dx;i++)
      {j+=z[i],p[i+1]=p[i]+j;
      k+=z[x[n]-i+2];
      r[i+1]=r[i]+k;}
for(i=x[1];i<=x[n]-dx;i++)
if(m>(k=p[i+1]+r[x[n]-dx-i+1]))
      m=k;
return m;}

int main()
{FILE *f=fopen("tribute.in","r"),*g=fopen("tribute.out","w");
fscanf(f,"%u%u%u",&n,&dx,&dy);
for(i=1;i<=n;i++)
      fscanf(f,"%u%u",&x[i],&y[i]);
fprintf(g,"%u",h(x,dx)+h(y,dy));
return 0;}