Pagini recente » Monitorul de evaluare | joaca_5 | Atasamentele paginii Clasament arhiva-test | Castori | Cod sursa (job #490069)
Cod sursa(job #490069)
#include <stdio.h>
#include <algorithm>
using namespace std;
int main ()
{
freopen("tribute.in", "r", stdin);
freopen("tribute.out", "w", stdout);
int n, i, a, dx, dy, vx[50001], vy[50001], max1=2000000000, max2=2000000000, k;
long long avg1=0, avg2=0;
scanf("%d %d %d", &n, &dx, &dy);
for (i=1; i<=n; i++) {
scanf("%d %d", &vx[i], &vy[i]);
}
for (i=1; i<=n; i++) {
avg1+=vx[i];
avg2+=vy[i];
}
avg1/=n;
avg2/=n;
for (a=avg1-dx; a<=dx; a++) {
k=0;
for (i=1; i<=n; i++) {
if (vx[i]<a) {
k+=(a-vx[i]);
} else if (vx[i]>a+dx) {
k+=(vx[i]-a);
}
}
if (k<max1) {
max1=k;
}
}
for (a=avg2-dy; a<=dy; a++) {
k=0;
for (i=1; i<=n; i++) {
if (vy[i]<a) {
k+=(a-vy[i]);
} else if (vy[i]>a+dy) {
k+=(vy[i]-a);
}
}
if (k<max2) {
max2=k;
}
}
k=max1+max2;
printf("%d", k);
return 0;
}