比赛 |
07级noip练习1 |
评测结果 |
EEEETTTTTA |
题目名称 |
纪念品分组 |
最终得分 |
10 |
用户昵称 |
bly1991 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-09-22 20:45:39 |
显示代码纯文本
program bly(input,ouput);
type
t1=array[1..100] of integer;
var
f1,f2:text;
g:t1;
i,j,left,right:integer;
n,s,ans,m:integer;
procedure QuickSort(var A: t1;Hi: Integer);
procedure Sort(l, r: Integer);
var
i, j, x, y: integer;
begin
i := l; j := r; x := a[(l+r) DIV 2];
repeat
while a[i] < x do i := i + 1;
while x < a[j] 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 l < j then Sort(l, j);
if i < r then Sort(i, r);
end;
begin {QuickSort};
Sort(1,Hi);
end;
begin
assign(f1,'group.in');
reset(f1);
readln(f1,s);
readln(f1,n);
for i:=1 to n do readln(f1,g[i]);
close(f1);
quicksort(g,n);
left:=1; right:=n; m:=0;
repeat
if g[left]+g[right]>s then begin
dec(right); inc(ans); m:=m+1;
end;
if g[left]+g[right]<=s then begin
inc(left); dec(right); inc(ans); m:=m+2;
end;
until left=right;
assign(f2,'group.out');
rewrite(f2);
if m+1=n then writeln(f2,ans+1)
else writeln(f2,ans);
close(f2);
end.