I am not Liar
Junior Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору program task_02_2; var a:array[0..100] of integer; b:array[-1..100] of integer; length:longint; n:byte; procedure init; var i,j:byte; o:integer; begin assign(input,'input.txt'); reset(input); readln(n); for i:=1 to n do read(a[i]); for j:=1 to n do begin for i:=j to n do begin if a[i]<a[j] then begin o:=a[j]; a[j]:=a[i]; a[i]:=o; end; end; end; close(input); end; function min(a,b:integer):integer; begin if a>=b then min:=b; if b>=a then min:=a; end; procedure work; var i,j:byte; begin b[-1]:=30000; b[0]:=0; for i:=1 to n do begin b[i]:=min(b[i-2],b[i-1])+a[i]-a[i-1]; end; end; begin init; work; assign(output,'output.txt'); rewrite(output); write(b[n]); close(output); end. |