Pagini recente » Cod sursa (job #1654054) | Cod sursa (job #2144229) | Cod sursa (job #2455496) | Cod sursa (job #2145671) | Cod sursa (job #170886)
Cod sursa(job #170886)
var a:array[1..1024] of longint;
nr,n,i,j,k,l,p:longint;
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
assign(input,'oite.in');
assign(output,'oite.out');
reset(input);
rewrite(output);
readln(n,l);
for i:=1 to n do read(a[i]);
sort(1,N);
for i:=1 to n do
if a[i]> l div 4 then break
else
for j:=i+1 to n do
for k:=j+1 to n do
for p:=j+1 to n do
if a[i]+a[j]+a[k]+a[p]=l then
inc(NR)
else if a[i]+a[j]+a[k]+a[p]>l then break;
writeln(nr);
end.