Cod sursa(job #2549464)

Utilizator alex_benescuAlex Ben alex_benescu Data 17 februarie 2020 18:33:23
Problema Tribute Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
using namespace std;
ifstream fin("tribute.in");
ofstream fout("tribute.out");
int n, dx, dy, i, t, pst[51000], pdr[51000], st[51000], dr[51000], sol, sol1, x, y, fx[51000], fy[51000];
int main(){
  fin>>n>>dx>>dy;
  for(i=1; i<=n; i++){
    fin>>x>>y;
    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];
  }
  fout<<sol1;
  return 0;
}