比赛 20101118 评测结果 AAWAAAAAAA
题目名称 分班 最终得分 90
用户昵称 ZhouZn1 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-18 08:43:40
显示代码纯文本
program zzn;
var
        l,r,n,i,j,sum,ans:longint;
        a,ne:array[1..50]of longint;
procedure swap(var a,b:longint);
var
        t:longint;
begin
        t:=a;
        a:=b;
        b:=t;
end;
procedure  init;
begin
        assign(input,'groupa.in');
        reset(input);
        assign(output,'groupa.out');
        rewrite(output);
        readln(n);
        sum:=0;
        for i:=1 to n do
        begin
        read(a[i]);
        inc(sum,a[i]);
        end;
        readln;
        readln(l,r);
        for i:=1 to n-1 do
         for j:=i+1 to n do if a[i]>a[j] then swap(a[i],a[j]);
end;
procedure closef;
begin
        close(input);
        close(output);
end;
procedure main;
var
        t1,t2:longint;
begin
        if (sum div n<l)or(sum div n>r )  then
         begin
             writeln(-1);
             exit;
         end;
        if (a[1]>=l)and(a[n]<=r) then
         begin
             writeln(0);
             exit;
         end;
        ans:=0;
        for i:=1 to n do
        begin
           if a[i]>r then ne[i]:=a[i]-r;
           if a[i]<l then ne[i]:=a[i]-l;
        end;
        t1:=0;t2:=0;
        for i:=1 to n do
         if ne[i]>0 then inc(t1,ne[i]) else inc(t2,abs(ne[i]));
        if t1>t2 then ans:=t1 else ans:=t2;
        writeln(ans);
end;
begin
        init;
        main;
        closef;
end.