Const fi = 'daycon.inp';
fo = 'daycon.oup';
var
a: array[0..1001] of longint;
tong: longint;
f,g : text;
n : integer;
Procedure docdulieu;
var i: integer;
begin
assign(f,fi); reset(f);
readln(f,n);
tong := 0;
for i := 1 to n do
begin
read(f,a[i]); tong := tong + a[i] ;
end;
close(f);
end;
Procedure sapxep;
var i,j : integer;
tg : longint;
begin
for i := 1 to n - 1 do
for j := i + 1 to n do
if a[i] > a[j] then
begin
tg := a[i]; a[i] := a[j]; a[j] := tg;
end
end;
Procedure xuli;
var i, kiluc : integer;
begin
kiluc := n;
sapxep;
i := n;
while i > 3 do
if a[i] + a[i-1] + a[i-2] > tong - (a[i] + a[i-1] + a[i-2]) then
begin
tong := tong - a[i];
dec(i); dec(kiluc);
end
else break;
assign(g,fo); rewrite(g);
if kiluc > 3 then writeln(g,kiluc) else write(g,0);
close(g);
end;
BEGIN
Docdulieu;
xuli;
END.
============================================
Admin đã có chỉnh sửa đôi chút!
fo = 'daycon.oup';
var
a: array[0..1001] of longint;
tong: longint;
f,g : text;
n : integer;
Procedure docdulieu;
var i: integer;
begin
assign(f,fi); reset(f);
readln(f,n);
tong := 0;
for i := 1 to n do
begin
read(f,a[i]); tong := tong + a[i] ;
end;
close(f);
end;
Procedure sapxep;
var i,j : integer;
tg : longint;
begin
for i := 1 to n - 1 do
for j := i + 1 to n do
if a[i] > a[j] then
begin
tg := a[i]; a[i] := a[j]; a[j] := tg;
end
end;
Procedure xuli;
var i, kiluc : integer;
begin
kiluc := n;
sapxep;
i := n;
while i > 3 do
if a[i] + a[i-1] + a[i-2] > tong - (a[i] + a[i-1] + a[i-2]) then
begin
tong := tong - a[i];
dec(i); dec(kiluc);
end
else break;
assign(g,fo); rewrite(g);
if kiluc > 3 then writeln(g,kiluc) else write(g,0);
close(g);
end;
BEGIN
Docdulieu;
xuli;
END.
============================================
Admin đã có chỉnh sửa đôi chút!