Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program lodki;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- var
- a: array [1..20000] of integer;
- n, k, i, j, f, t: integer;
- boo: array [1..20000] of boolean;
- procedure qsort(min, max: Integer);
- var
- i, j, s, t: integer;
- begin
- s := a[max - ((max - min) div 2)];
- i := min;
- j := max;
- while (i < j) do
- begin
- while a[i] < s do i := i + 1;
- while a[j] > s do j := j - 1;
- if i <= j then
- begin
- t := a[i];
- a[i] := a[j];
- a[j] := t;
- i := i + 1;
- j := j - 1;
- end;
- end;
- if min < j then qsort(min, j);
- if i < max then qsort(i, max);
- end;
- begin
- readln(n, k);
- f := 0;
- for i := 1 to n do read(a[i]);
- qsort(0, n);
- for i := n downto 1 do
- if not (boo[i]) then
- begin
- boo[i] := true;
- inc(f);
- t := k - a[i];
- j := i - 1;
- while (t > 0) and (j > 0) do
- if (not boo[j]) and (t - a[j] >= 0) then
- begin
- boo[j] := true;
- dec(t, a[j]);
- dec(j);
- end
- else dec(j);
- end;
- writeln(f);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement