Cod sursa(job #7282)

Utilizator DarkieBretan Andrei Vlad Darkie Data 21 ianuarie 2007 13:18:42
Problema 1-sir Scor 0
Compilator fpc Status done
Runda preONI 2007, Runda 1, Clasele 11-12 Marime 0.8 kb
var v:array[1..256] of byte;
var f:text;
var sum,max,x,poz,i,a,n,s:longint;
begin
 assign(f,'1-sir.in'); reset(f);
 read(f,n); read(f,s);
 close(f);
 assign(f,'1-sir.out'); rewrite(f);
 if s>2134 then write(f,'0') else
 begin
  for i:=1 to n do
   begin
    if i>10 then if i mod 2=0 then v[i]:=9
                              else v[i]:=8
            else v[i]:=i-1;
   end;
  repeat
   sum:=0;
   for i:=1 to n do
    sum:=sum+v[i];
   max:=0;
   for i:=1 to n do
    if max<v[i] then max:=v[i];
   for i:=1 to n do
    if v[i]=max then poz:=i;
   if sum>s then v[poz]:=v[poz]-2
             else begin
                   x:=0;
                   for i:=1 to n do
                    if v[i]=0 then x:=x+1;
                  end;
  until sum=s;
  write(f,x);
end;
close(f);
end.