为什么WA60

为什么60WA
program Project1;

var
i, j, n, w, ans: longint;
a: array[1..10000] of longint;

procedure qsort(l, r: longint);
var
i, j, x, y: longint;
begin
i := l;
j := r;
x := a[(l + r) div 2];
repeat
while a[i] < x do
Inc(i);
while a[j] > x do
Dec(j);
if i <= j then
begin
y := a[i];
a[i] := a[j];
a[j] := y;
Inc(i);
Dec(j);
end;
until i > j;
if i < r then
qsort(i, r);
if l < j then
qsort(l, j);
end;

begin
readln(w);
readln(n);
ans := 0;
for i := 1 to n do
readln(a[i]);
qsort(1, n);
for i := 1 to n - 1 do
for j := n downto i + 1 do
begin
if a[i] + a[i + 1] > w then
begin
Inc(ans);
break;
end
else
if (a[i] + a[j] <= w) and (a[j] <> 0) and (a[i + 1] <> 0) then
begin
a[i] := 0;
a[j] := 0;
Inc(ans);
break;
end
else if (a[i] <> 0) and (a[i+1] = 0) then
begin
Inc(ans);
a[i] := 0;
break;
end;
end;
if a[n] <> 0 then
Inc(ans);
writeln(ans);
end.

0 条评论

目前还没有评论...

信息

ID
1409
难度
4
分类
贪心 点击显示
标签
递交数
8093
已通过
3186
通过率
39%
被复制
25
上传者