Pagini recente » Cod sursa (job #1572662) | Cod sursa (job #2117141) | Cod sursa (job #620763) | Cod sursa (job #55678) | Cod sursa (job #1814187)
#include <cstdio>
#include <algorithm>
#include <climits>
using namespace std;
FILE *f, *g;
int n;
long long lx, ly;
long long mnx, mny;
long long x[50001], y[50001];
long long sx[50001], sy[50001];
void readFile()
{
f = fopen("tribute.in", "r");
int i;
fscanf(f, "%d%lld%lld", &n, &lx, &ly);
for(i = 1; i <= n; i ++)
{
fscanf(f, "%d%d", &x[i], &y[i]);
}
fclose(f);
}
void solve()
{
int i, j;
int first = 0, last;
sort(x + 1, x + n + 1);
sort(y + 1, y + n + 1);
for(i = 1; i <= n; i ++)
{
if(x[i] > lx)
{
if(sx[0] == 0)
last = i;
sx[0] += (x[i] - lx);
}
}
mnx = sx[0];
for(i = 1; i <= n - lx; i ++)
{
while(last < n && x[last] < i + lx)
last ++;
while(first < n && x[first] < i)
first ++;
sx[i] = sx[i - 1] - ((n - last + 1) * ((n - last + 1) != 1)) + (first - 1);
if(sx[i] < mnx)
mnx = sx[i];
}
first = 1;
for(i = 1; i <= n; i ++)
{
if(y[i] > ly)
{
if(sy[0] == 0)
last = i;
sy[0] += (y[i] - ly);
}
}
mny = sy[0];
for(i = 1; i <= n - ly; i ++)
{
while(last < n && y[last] < i + ly)
last ++;
while(first < n && y[first] < i)
first ++;
sy[i] = sy[i - 1] - ((n - last + 1) * ((n - last + 1) != 1)) + (first - 1);
if(sy[i] < mny)
mny = sy[i];
}
}
void printFile()
{
g = fopen("tribute.out", "w");
fprintf(g, "%lld\n", mnx + mny);
fclose(g);
}
int main()
{
readFile();
solve();
printFile();
return 0;
}