Cod sursa(job #2614856)

Utilizator alex_benescuAlex Ben alex_benescu Data 12 mai 2020 19:22:35
Problema Tribute Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <stdio.h>
#include <iostream>
#define MAXLOG10 10
#define BUFSIZE (128*1024)
using namespace std;
int pst[51000], pdr[51000], st[51000], dr[51000], fx[51000], fy[51000];
int p10[MAXLOG10+1]={0, 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
int rpos; char rbuf[BUFSIZE];
static inline void initRead(){
  rpos=BUFSIZE-1;
}
static inline char readChar(){
  if(!(rpos=(rpos+1) & (BUFSIZE-1)))
    fread(rbuf, 1, BUFSIZE, stdin);
  return rbuf[rpos];
}
int readInt(){
  int ch, res=0;
  while(isspace(ch=readChar()));
  do
    res=10*res+ch-'0';
  while(isdigit(ch=readChar()));
  return res;
}
int main(){
  freopen("tribute.in", "r", stdin);
  freopen("tribute.out", "w", stdout);
  initRead();
  int n, dx, dy, i, t, sol, sol1=0, x, y;
  n=readInt();
  dx=readInt();
  dy=readInt();
  for(i=1; i<=n; i++){
    x=readInt();
    y=readInt();
    fx[x]++;
    fy[y]++;
  }
  for(t=1; t<3; t++){
    st[0]=0;
    pst[0]=fx[0];
    for(i=1; i<=50000; i++){
      st[i]=st[i-1]+pst[i-1];
      pst[i]=pst[i-1]+fx[i];
    }
    dr[50000]=0;
    pdr[50000]=fx[50000];
    for(i=49999; i>=0; i--){
      dr[i]=dr[i+1]+pdr[i+1];
      pdr[i]=pdr[i+1]+fx[i];
    }
    sol=2000000000;
    for(i=0; i+dx<=50000; i++)
      sol=min(sol, dr[i+dx]+st[i]);
    sol1+=sol;
    dx=dy;
    for(i=0; i<=50000; i++)
      fx[i]=fy[i];
  }
  printf("%d\n", sol1);
  return 0;
}