比赛 |
20101118 |
评测结果 |
AWAWWAATTT |
题目名称 |
分班 |
最终得分 |
40 |
用户昵称 |
magic |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-18 09:49:32 |
显示代码纯文本
program gls;
var
ss:array[1..50]of int64;{ke neng yao gai}
a,b,c,k,n,he,head,tail,p:longint;
f,g:text;
procedure Sort(l, r: longint);
var
i, j, x, y: longint;
begin
i := l; j := r; x := ss[(l+r) DIV 2];
repeat
while ss[i] < x do i := i + 1;
while x < ss[j] do j := j - 1;
if i <= j then
begin
y := ss[i]; ss[i] := ss[j]; ss[j] := y;
i := i + 1; j := j - 1;
end;
until i > j;
if l < j then Sort(l, j);
if i < r then Sort(i, r);
end;
function success:boolean;
var flag:boolean;k:longint;
begin flag:=true;
for k:=1 to n do
if (ss[k]<a)or(ss[k]>b)
then flag:=false;
success:=flag;
end;
begin
assign(f,'groupa.in');
reset(f);
assign(g,'groupa.out');
rewrite(g);
readln(f,n);
for k:=1 to n do
begin read(f,ss[k]);
he:=he+ss[k];
end;
readln(f,a,b);
sort(1,n);
head:=1;
if ss[n]>b then begin
for k:=1 to n do if ss[k]>b then
begin tail:=k;
break;
end; end else for k:=1 to n do
begin if ss[k]>a then
begin tail:=k;
break;
end;
end;
if ((he/n>b) or (he/n<a)) then write(g,'-1') else
begin
repeat begin if ss[head]<b then
begin
repeat begin
if ss[head]+1>b then head:=1;
dec(ss[tail]);
inc(ss[head]);
inc(p);
if head+1<=n then if ss[head]=a then inc(head);
if tail+1<=n then if ss[tail]=b then inc(tail);
end;until ((ss[head]=a)or(ss[head]=b))and(ss[tail]<=b);
end;
end;
until success;
writeln(g,p);
end;
close(g);close(f);
end.