fork download
  1. program diafora(input, output);
  2. var N, i, j, temp, thesi, min : integer;
  3. a : array[1..1000000] of integer;
  4.  
  5. begin
  6. readln(N);
  7. thesi:= 0;
  8. i:= 0;
  9. while i < N do
  10. begin
  11. i:= i + 1;
  12. read(a[i]);
  13. if a[i] > 0 then thesi:= i
  14. end;
  15. readln;
  16. if thesi = 1 then writeln(a[1] + a[2])
  17. else if thesi = 0 then writeln(a[N - 1] + a[N])
  18. else
  19. begin
  20. if thesi < N then min:= a[thesi] + a[thesi + 1];
  21. if thesi > 2 then temp:= -(a[thesi - 1] + a[thesi - 2]);
  22. if temp < min then min:= temp;
  23. i:= 0;
  24. j:= thesi - 1;
  25. while i < thesi - 2 do
  26. begin
  27. i:= i + 1;
  28. while j < N do
  29. begin
  30. j:= j + 1;
  31. temp:= a[i] + a[j];
  32. if abs(temp) < abs(min) then min:= temp
  33. end
  34. end;
  35. writeln(min)
  36. end
  37. end.
Success #stdin #stdout 0.01s 8020KB
stdin
3
1 4 9
stdout
-5