Pagini recente » Cod sursa (job #1587781) | Cod sursa (job #993434) | Cod sursa (job #343693) | Cod sursa (job #1498014) | Cod sursa (job #1044456)
#include <fstream>
#include <vector>
#include <bitset>
#include <string.h>
using namespace std;
const char infile[] = "tribute.in";
const char outfile[] = "tribute.out";
ifstream fin(infile);
ofstream fout(outfile);
const int MAXN = 50005;
const int oo = 0x3f3f3f3f;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
const inline int min(const int &a, const int &b) { if( a > b ) return b; return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b; return a; }
const inline void Get_min(int &a, const int b) { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b) { if( a < b ) a = b; }
int N, Dx, Dy, freqx[MAXN], freqy[MAXN], many[MAXN], st[MAXN], dr[MAXN], sus[MAXN], jos[MAXN];
int main() {
fin >> N >> Dx >> Dy;
for(int i = 1 ; i <= N ; ++ i) {
int x, y;
fin >> x >> y;
++ freqx[x]; ++ freqy[y];
}
memset(many, 0, sizeof(many));
for(int i = 0 ; i < MAXN ; ++ i) {
st[i] = many[i-1] + st[i-1];
many[i] = many[i-1] + freqx[i];
}
memset(many, 0, sizeof(many));
for(int i = MAXN - 1 ; i >= 0; -- i) {
dr[i] = many[i+1] + dr[i+1];
many[i] = many[i+1] + freqx[i];
}
int Ans1 = oo;
for(int i = 0 ; i + Dx < MAXN ; ++ i)
Get_min(Ans1, st[i] + dr[i + Dx]);
memset(many, 0, sizeof(many));
for(int i = 0 ; i < MAXN ; ++ i) {
sus[i] = many[i-1] + sus[i-1];
many[i] = many[i-1] + freqy[i];
}
memset(many, 0, sizeof(many));
for(int i = MAXN - 1 ; i >= 0; -- i) {
jos[i] = many[i+1] + jos[i+1];
many[i] = many[i+1] + freqy[i];
}
int Ans2 = oo;
for(int i = 0 ; i + Dx < MAXN ; ++ i)
Get_min(Ans2, sus[i] + jos[i + Dx]);
fout << Ans1 + Ans2 << '\n';
fin.close();
fout.close();
return 0;
}