Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var a,b:array of integer;
- i,j,k,n,x,m,sa,sb,min:integer;
- begin
- readln(n);
- min:=10000000000;
- for i:=1 to n do begin
- readln(x,m);
- if(m = 1) then begin
- setlength(a,length(a)+1);
- a[length(a)-1]:=x;
- sa+=x;
- end;
- if(m = 2) then begin
- setlength(b,length(b)+1);
- b[length(b)-1]:=x;
- sb+=x;
- end;
- end;
- for i:=0 to length(a)-1 do begin
- if (abs((sb+a[i])-(sa-a[i])) < min) then min:= abs((sb+a[i])-(sa-a[i]));
- end;
- for i:=0 to length(b)-1 do begin
- if (abs((sa+b[i])-(sb-b[i])) < min) then min:= abs((sa+b[i])-(sb-b[i]));
- end;
- if (abs(sa-sb)<min) then min:=abs(sa-sb);
- write(min);
- end.
Add Comment
Please, Sign In to add comment