比赛 20101118 评测结果 AAAAWAAAWW
题目名称 分班 最终得分 70
用户昵称 DeiTy 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-18 09:45:22
显示代码纯文本
program groupa;
var
   n,i,j,l,r,t,h,m:longint;
   a,b:array[1..50] of longint;
 begin
   assign(input,'groupa.in');
   assign(output,'groupa.out');
   reset(input);
   rewrite(output);
   readln(n);
   for i:=1 to n do read(a[i]);
   readln(l,r);
   for i:=1 to n do b[i]:=a[i]-l;
   for i:=1 to n do h:=h+b[i];
   if (h>(n*(r-l))) or (h<0)
     then begin
            writeln(-1);
            close(input);
            close(output);
            halt;
          end;
   for i:=1 to n-1 do
     for j:=i+1 to n do
     if b[i]<b[j] then begin
                         t:=b[i];
                         b[i]:=b[j];
                         b[j]:=t;
                       end
                  else begin
                         t:=b[i];
                         b[i]:=b[j];
                         b[j]:=t;
                       end;
   for i:=1 to n do
     if b[i]>(r-l) then m:=m+b[i]-(r-l);
   writeln(m);
   close(input);
   close(output);
end.