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 1005. Stone Pile

WA on test №1. Where is mistake in my program?
Posted by DixonD (LNU) 23 Oct 2006 02:03
program Project1;


var a:array [1..20] of integer;
    n,i:byte;
    suma:integer;
    suma1,sumaTemp:integer;
procedure rekurs(k:byte);
var i:byte;
begin
  for I:=k to n do
   begin
    dec(sumaTemp,a[i]);
    if sumaTemp>=0 then
       if sumaTemp=0 then begin
   writeln(suma-suma1*2); halt(13) end
         else rekurs(i+1);
    inc(sumaTemp,a[i]);
   end;
end;

begin
 suma:=0;
 readln(n);
 for i:=1 to n do
   begin
   readln(a[i]);
   inc(suma,a[i]);
   end;
 if n=1 then writeln(suma) else
 begin
 suma1:=suma div 2;
 while suma1>0 do
  begin
   sumaTemp:=suma1;
   rekurs(1);
   dec(suma1);
  end;
end;
end.