Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

What's Wrong? Thx a lot...

Posted by kyd at 2009-06-07 16:13:27 on Problem 3627
{
PROG:shelf
LANG:PASCAL
ID:kydmail1
}
program poj_shelf3627;
var
  a:array [0..20000] of integer;
  n,b,i,j:integer;
  s:longint;
procedure qsort(s,t:integer);
        var
          i,j,mid:integer;
        begin
            i:=s;
            j:=t;
            mid:=a[s];
            while (i<j) do
                begin
                    while (i<j) and (a[j]>=mid) do dec(j);
                    if (i<j) then a[i]:=a[j];
                    while (i<j) and (a[i]<=mid) do inc(i);
                    if i<j then a[j]:=a[i];
                end;
            a[i]:=mid;
            if s<i-1 then qsort(s,i-1);
            if i+1<t then qsort(i+1,t);
        end;
begin
{assign(input,'shelf.in');
assign(output,'shelf.out');
reset(input);
rewrite(output);         }
readln(n,b);
fillchar(a,sizeof(a),0);
for i:=1 to n do
  readln(a[i]);
qsort(1,n);
s:=0;
for i:=1 to n do
  begin
      s:=s+a[n-i+1];
      if s>=b then break;
  end;
writeln(i);


{close(output);}
end.


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator