2 a
,b
,f
,g
:array [0..1000] of longint;
7 for i
:=1 to n
do begin readln(a
[i
],b
[i
]); inc(f
[1],a
[i
]-b
[i
]); g
[i
]:=maxlongint
; end;
11 if abs(f
[j
]+2*(b
[i
]-a
[i
]))<f
[i
] then begin f
[i
]:=f
[j
]+2*(b
[i
]-a
[i
]); g
[i
]:=g
[j
]+1; end
13 if (g
[j
]<g
[i
]) then begin f
[i
]:=f
[j
]; g
[i
]:=g
[j
]; end;
16 close(input
); close(output
);