Cod sursa(job #1690365)

Utilizator alexandru70Ungurianu Alexandru alexandru70 Data 15 aprilie 2016 01:16:53
Problema Tribute Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream in("tribute.in");
ofstream out("tribute.out");

int main(int argc, char const *argv[]) {

  int n;
  in >> n;

  int dx,dy;
  in >> dx >> dy;

  vector<int> xs(50001),ys(50001);

  for(int i = 0; i < n; ++i) {
    int x,y;
    in >> x >> y;
    xs[x]++;
    ys[y]++;
  }

  for(int i = 0; i < xs.size(); ++i) {
    xs[i] += xs[i-1];
  }

  for(int i = 0; i < ys.size(); ++i) {
    ys[i] += ys[i-1];
  }

  int startXIdx = 0;
  int minDistX = xs.back()-xs[dx];

  for(int i = 1; i < xs.size(); ++i) {
    int curDistX = xs[i-1] + xs.back()-xs[min(i+dx+1,xs.size()-1)];
    if(curDistX < minDistX) {
      minDistX = curDistX;
      startXIdx = i;
    }
  }

  int startYIdx = 0;
  int minDistY = ys.back()-ys[dy];


  for(int i = 1; i < ys.size(); ++i) {
    int curDistY = ys[i-1] + ys.back()-ys[min(i+dy+1,ys.size()-1)];
    if(curDistY < minDistY) {
      minDistY = curDistY;
      startYIdx = i;
    }
  }

  out << minDistX + minDistY << '\n';
}