Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var n,i,j,luu,s:integer;
- a,L:array[0..200] of integer;
- fi,fo:text;
- procedure KT();
- begin
- for i:=1 to n do
- for j:=s downto a[i] do
- if (L[j]=0) and (L[j-a[i]]=1) then L[j]:=1;
- end;
- begin
- assign(fi,'candy1046.inp');
- reset(fi);
- readln(fi,n);
- for i:=1 to n do
- read(fi,a[i]);
- close(fi);
- s:=0;
- for i:= 1 to n do
- s:=s+a[i];
- luu:=s; s:=trunc(s/2);
- for i:=1 to s do
- L[i]:=0;
- L[0]:=1;
- KT;
- while L[s]<>1 do s:=s-1;
- // write('Phan thu nhat ',s,' cai keo'); writeln;
- // write('Phan thu hai ',luu-s,' cai keo');
- assign(fo,'candy1046.out');
- rewrite(fo);
- write(fo,luu-s*2);
- close(fo);
- readln
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement