0% found this document useful (0 votes)
22 views1 page

Min Difference in Pascal Array

The document contains a Pascal program that reads an integer N and an array of LongInt values. It calculates the minimum absolute difference between the sum of the first i elements and the sum of the remaining elements for all possible splits of the array. The result is printed as the minimum difference found.

Uploaded by

Đỗ Hoàng Nam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views1 page

Min Difference in Pascal Array

The document contains a Pascal program that reads an integer N and an array of LongInt values. It calculates the minimum absolute difference between the sum of the first i elements and the sum of the remaining elements for all possible splits of the array. The result is printed as the minimum difference found.

Uploaded by

Đỗ Hoàng Nam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

type MyAr = array[1..

10000] of LongInt;
var A : MyAr;
N,X,Y,i,j,k,min : LongInt;
begin
readln(N);
X := 0;
Y := 0;
min := 10001;
for i := 1 to n do begin
read(A[i]);
for j := 1 to i do X += A[j];
for k := i+1 to n do Y += A[k];
if min > abs(X-Y) then min := abs(X-Y);
end;
writeln(min);
end.

You might also like