CTNEWS - Lâu đài cát
Tác giả: flashmt
Ngôn ngữ: Pascal
const fi='';
fo='';
maxn=25000;
type ar=array[1..maxn] of longint;
var n,x,y,re:longint;
a,b:ar;
procedure rf;
var i:longint;
begin
assign(input,fi);
reset(input);
read(n,x,y);
for i:=1 to n do read(a[i],b[i]);
close(input);
end;
procedure sort(var a:ar;l,r:longint);
var x,y,i,j:longint;
begin
i:=l; j:=r; x:=a[(i+j) div 2];
repeat
while a[i]<x do i:=i+1;
while a[j]>x do j:=j-1;
if i<=j then
begin
y:=a[i]; a[i]:=a[j]; a[j]:=y;
i:=i+1; j:=j-1;
end;
until i>j;
if i<r then sort(a,i,r);
if l<j then sort(a,l,j);
end;
procedure pr;
var i:longint;
begin
re:=0;
sort(a,1,n);
sort(b,1,n);
for i:=1 to n do
if a[i]<b[i] then re:=re+x*(b[i]-a[i])
else re:=re+y*(a[i]-b[i]);
end;
procedure wf;
begin
assign(output,fo);
rewrite(output);
write(re);
close(output);
end;
begin
rf;
pr;
wf;
end.