Advertisement
tuki2501

candy1046.pas

Nov 12th, 2021
1,525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.65 KB | None | 0 0
  1. var n,i,j,luu,s:integer;
  2.     a,L:array[0..200] of integer;
  3.     fi,fo:text;
  4.  
  5. procedure KT();
  6. begin
  7.    for i:=1 to n do
  8.     for j:=s downto a[i] do
  9.      if (L[j]=0) and (L[j-a[i]]=1) then L[j]:=1;
  10. end;
  11.  
  12. begin
  13.  assign(fi,'candy1046.inp');
  14.  reset(fi);
  15.  readln(fi,n);
  16.  for i:=1 to n do
  17.   read(fi,a[i]);
  18.  close(fi);
  19.  s:=0;
  20.  for i:= 1 to n do
  21.   s:=s+a[i];
  22.  luu:=s; s:=trunc(s/2);
  23.  for i:=1 to s do
  24.   L[i]:=0;
  25.  L[0]:=1;
  26.  KT;
  27.  while L[s]<>1 do s:=s-1;
  28.  // write('Phan thu nhat ',s,' cai keo'); writeln;
  29.  // write('Phan thu hai ',luu-s,' cai keo');
  30.  assign(fo,'candy1046.out');
  31.  rewrite(fo);
  32.  write(fo,luu-s*2);
  33.  close(fo);
  34. readln
  35. end.
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement