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

Why does not pass the first test???? (1005)
Posted by Виктор Крупко 27 Mar 2005 00:56
program perebor;
    var
    a,b:array[1..20] of longint;
    i,n,otv:longint;
procedure profi(sum1:longint);
   var
   j,sum2,ff:longint;
begin
   sum2:=0;
   if i<=n then
   begin
    for j:=1 to n do
    if a[j]<>0 then sum2:=sum2+a[j];

    if sum2>sum1 then ff:=sum2-sum1
    else ff:=sum1-sum2;

    if ff<otv then otv:=ff;

    for j:=1 to n do
     if a[j]<>0 then
      begin
       i:=i+1;
       sum1:=sum1+a[j];
       a[j]:=0;
       profi(sum1);
       sum1:=sum1-b[j];
       a[j]:=b[j];
       i:=i-1;
      end;
    end;
end;
begin
   otv:=maxlongint;
   readln(n);
   for i:=1 to n do
   begin
    readln(a[i]);
    b[i]:=a[i];
   end;
   i:=0;
   profi(0);
   write(otv);
end.

Edited by author 27.03.2005 00:58