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 WA#1
Posted by Mad_Sanek 8 Aug 2012 00:54
type
list = array[1..21] of longint;

var n,i,w1,w2,d:integer;
w:list;

begin
read(n);
d:=0;
For i:=1 to n do read(w[i]);
If n=1 then begin write(w[1]); halt; end;
For i:=1 to n div 2 do begin
  If w1>w2 then w2:=w2+abs(w[i+d]-w[i+d+1]) else w1:=w1+abs(w[i+d]-w[i+d+1]);
  d:=d+1;
  end;
If n mod 2=0 then write(abs(w1-w2)) else write(w[n]-abs(w1-w2));
end.

1
1
is correct(1).

5
1 8 13 27 14
is correct(3).
Test #5 is correct. Where is the mistake?

Edited by author 08.08.2012 01:02