ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1796. Amusement Park

tle on test 5 please help pascal
Posted by amirani 18 Jan 2012 17:50
var
      i,k,j,p,min,q,x,n:integer;
      a,b:array [1..6] of integer;
      c:array [0..6] of integer;
      t:boolean;
begin
   min:=32000;
   a[1]:=10;
   a[2]:=50;
   a[3]:=100;
   a[4]:=500;
   a[5]:=1000;
   a[6]:=5000;
   n:=6;
   for i:=1 to n-1 do
   begin
      read (b[i]);
      x:=x+b[i]*a[i];
   end;
   readln (b[n]);
   readln (k);
   t:=false;
   i:=1;
   while not t do
      begin
          while  (i<=n) and (c[i]>=b[i]) do
         begin
            c[i]:=0;
                inc(i);
         end;
      if i>n then
             begin
            t:=true;
                continue;
             end;
      inc(c[i]);
      for j:=1 to n do
        p:=p+c[j]*a[j];
       if p=k then
       begin
          q:=p;
          break;
       end;
       if p>=k then
          begin
             for j:=1 to i-1 do
            c[j]:=0;

          end
       else
          i:=1;
      if  (p>=k) and (p-k<min) then
        begin
           min:=p-k;
               q:=p;
        end;
      end;
   q:=(x-q) div k;
   writeln ((x div k)-q);
   for i:=q+1 to x div k do
      write (i,' ');

end.