1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | program exetasi1(input,output); var n,i,j,position,sum0,min : integer; a : array[1..1000000] of integer; begin readln(n); for i := 1 to n do read(a[i]); if a[1]>0 then sum0 := (a[1] + a[2]) else if a[n]<0 then sum0 := ( a[n] + a[n - 1]) else begin sum0 := 2*1000000000; for i := 1 to n do begin if a[n]>0 then position := a[n-1]; end; for i := 1 to position do begin for j := (position + 1) to (n - 1) do begin if ((abs(a[j])<abs(a[i])) and (abs(a[j + 1])> abs(a[i]))) then begin if abs(a[i] + a[j])< abs(a[i] + a[j + 1]) then min := abs(a[i] + a[j]) else min := abs(a[i] + a[j + 1]) end; if abs(min)<abs(sum0) then sum0 := min end end; if position<=( n - 2) then begin if (a[position + 1] + a[position + 2])<abs(sum0) then sum0 := (a[position + 1] + a[position + 2]) end; if position >= 3 then begin if abs(a[position - 1] + a[position])< abs(sum0) then sum0 := (a[position] + a[position - 1]) end end; writeln(sum0) end. |
cHJvZ3JhbSBleGV0YXNpMShpbnB1dCxvdXRwdXQpOwoJdmFyICBuLGksaixwb3NpdGlvbixzdW0wLG1pbiA6IGludGVnZXI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhIDogYXJyYXlbMS4uMTAwMDAwMF0gb2YgaW50ZWdlcjsKCmJlZ2luCiAgIHJlYWRsbihuKTsKICAgZm9yIGkgOj0gMSB0byBuIGRvIHJlYWQoYVtpXSk7CiAgIGlmIGFbMV0+MCB0aGVuIHN1bTAgOj0gKGFbMV0gKyBhWzJdKQogICBlbHNlIGlmIGFbbl08MCB0aGVuIHN1bTAgOj0gKCBhW25dICsgYVtuIC0gMV0pCiAgIGVsc2UKICAgYmVnaW4KICAgICAgc3VtMCA6PSAyKjEwMDAwMDAwMDA7CiAgICAgIGZvciBpIDo9IDEgdG8gbiBkbwogICAgICBiZWdpbgogICAgICAgIGlmIGFbbl0+MCB0aGVuIHBvc2l0aW9uIDo9IGFbbi0xXTsKICAgICAgZW5kOwogICAgICBmb3IgaSA6PSAxIHRvIHBvc2l0aW9uIGRvCiAgICAgIGJlZ2luCiAgICAgICAgIGZvciBqIDo9IChwb3NpdGlvbiArIDEpIHRvIChuIC0gMSkgZG8KICAgICAgICAgYmVnaW4KICAgICAgICAgICAgICBpZiAoKGFicyhhW2pdKTxhYnMoYVtpXSkpIGFuZCAoYWJzKGFbaiArIDFdKT4gYWJzKGFbaV0pKSkgdGhlbgogICAgICAgICAgICAgIGJlZ2luCiAgICAgICAgICAgICAgICBpZiBhYnMoYVtpXSArIGFbal0pPCBhYnMoYVtpXSArIGFbaiArIDFdKSB0aGVuIG1pbiA6PSBhYnMoYVtpXSArIGFbal0pCiAgICAgICAgICAgICAgICBlbHNlIG1pbiA6PSBhYnMoYVtpXSArIGFbaiArIDFdKQogICAgICAgICAgICAgIGVuZDsKICAgICAgICAgICAgICBpZiBhYnMobWluKTxhYnMoc3VtMCkgdGhlbiBzdW0wIDo9IG1pbgogICAgICAgICBlbmQKICAgICAgIGVuZDsKICAgICAgIGlmIHBvc2l0aW9uPD0oIG4gLSAyKSB0aGVuIAogICAgICAgYmVnaW4KICAgICAgICAgaWYgKGFbcG9zaXRpb24gKyAxXSArIGFbcG9zaXRpb24gKyAyXSk8YWJzKHN1bTApIHRoZW4gc3VtMCA6PSAoYVtwb3NpdGlvbiArIDFdICsgYVtwb3NpdGlvbiArIDJdKQogICAgICAgZW5kOwogICAgICAgaWYgcG9zaXRpb24gPj0gMyB0aGVuIAogICAgICAgYmVnaW4KICAgICAgICAgaWYgYWJzKGFbcG9zaXRpb24gLSAxXSArIGFbcG9zaXRpb25dKTwgYWJzKHN1bTApIHRoZW4gc3VtMCA6PSAoYVtwb3NpdGlvbl0gKyBhW3Bvc2l0aW9uICAtIDFdKQogICAgICAgZW5kCiAgZW5kOwogIHdyaXRlbG4oc3VtMCkKZW5kLgogICAgICAgICAgCiAgICAgICA=
-
upload with new input
-
result: Runtime error time: 0.02s memory: 8020 kB signal: -1
-101 -4 -1 6 95
./prog: value out of range (error #300 at 804a0a8)
-
result: Runtime error time: 0.02s memory: 8020 kB signal: -1
./prog: attempt to read past end of Input (error #454 at 804a007)



