RadioNurshat

Ton's work 1

Oct 13th, 2020 (edited)
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.66 KB | None | 0 0
  1. var a,b:array of integer;
  2. i,j,k,n,x,m,sa,sb,min:integer;
  3. begin
  4.   readln(n);
  5.   min:=10000000000;
  6.   for i:=1 to n do begin
  7.  
  8.  
  9.   readln(x,m);
  10.   if(m = 1) then begin
  11.     setlength(a,length(a)+1);
  12.     a[length(a)-1]:=x;
  13.     sa+=x;
  14.   end;
  15.   if(m = 2) then begin
  16.     setlength(b,length(b)+1);
  17.     b[length(b)-1]:=x;
  18.     sb+=x;
  19.   end;
  20.   end;
  21.   for i:=0 to length(a)-1 do begin
  22.     if (abs((sb+a[i])-(sa-a[i])) < min) then min:= abs((sb+a[i])-(sa-a[i]));
  23.     end;
  24.    for i:=0 to length(b)-1 do begin
  25.     if (abs((sa+b[i])-(sb-b[i])) < min) then min:= abs((sa+b[i])-(sb-b[i]));
  26.     end;
  27.    if (abs(sa-sb)<min) then min:=abs(sa-sb);
  28.    write(min);
  29. end.
Add Comment
Please, Sign In to add comment