比赛 20101118 评测结果 AAAWWAEWWW
题目名称 分班 最终得分 40
用户昵称 sr-end 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-18 10:12:59
显示代码纯文本
program aa;
var
head,tail,x:integer;
a:array[1..100] of integer;
f,f1:text;
k:real;
n,l,r,s,v,sort:integer;
i,j:integer;
function zai(b:integer):boolean;
begin
 if  (b<=r)and(b>=l) then zai:=true
 else zai:=false;
 end;
begin
k:=0;
s:=0;
assign(f,'groupa.in'); assign(f1,'groupa.out');
reset(f);
rewrite(f1);
readln(f,n);
for i:=1 to n do
read(f,a[i]);
readln(f);
read(f,l,r);
for i:=1 to n do
 k:=k+a[i];
 if (k/n<l) or (k/n>r) then
 begin
 write(f1,'-1');
 end
  else
  begin
   for i:=1 to n do
    if zai(a[i]) then inc(s);
    if s=n then
    begin
    write(f1,0);
    end
    else
    begin
    for i:=1 to n-1 do
     for j:=i to n do
      if a[i]<a[j] then    begin
      sort:=a[i];
      a[i]:=a[j];
      a[j]:=sort;
      end;
head:=1;
tail:=n;
repeat
repeat
 if (a[head]>l)or (a[tail]<l) then
 begin
  dec(a[head]);
  inc(a[tail]);
  x:=x+1;
 end;
 until
 (a[head]>=l) or (a[tail]>=l);
      if a[head]<=l then inc(head);
      if a[tail]>=l then dec(tail);
      until
      head=tail;
      v:=a[head]-r;
 write(f1,x+v);
end;
end;
close(f);close(f1);
end.