比赛 20101101 评测结果 WWWWWWWWWW
题目名称 奇怪的监狱 最终得分 0
用户昵称 Abel·S 运行时间 0.004 s
代码语言 Pascal 内存使用 0.17 MiB
提交时间 2012-11-05 10:32:35
显示代码纯文本
program cojs_p929;
type
	pri=array[0..1001] of longint;
var
	pos,dis:pri;
	n,m,i,j,k,sum:longint;
procedure ass;
begin
	assign(input,'prison.in');
	assign(output,'prison.out');
	reset(input);
	rewrite(output);
end;
procedure cls;
begin
	close(input);
	close(output);
end;
procedure swap(var a,b:longint);
var
	t:longint;
begin
	t:=a;
	a:=b;
	b:=t;
end;
procedure sort(l,r:longint; var a:pri);
var
	i,j,x:longint;
begin
	i:=l;
	j:=r;
	x:=a[(l+r) div 2];
	repeat
		while a[i]<x do inc(i);
		while x<a[j] do dec(j);
		if i<=j then begin swap(a[i],a[j]); inc(i); dec(j); end;
	until i>j;
	if i<r then sort(i,r,a);
	if l<j then sort(l,j,a);
end;
procedure init;
var
	i:longint;
begin
	ass;
	readln(n,m);
	pos[0]:=0;
	for i:=1 to m do
		read(pos[i]);
	sort(1,m,pos);
	for i:=1 to m do
		dis[i]:=pos[i]-pos[i-1]-1;
	dis[m+1]:=n-pos[m];
	sort(1,m+1,dis);
end;
begin
	init;
	sum:=0;
	for i:=m+1 downto 2 do
		sum:=sum+(dis[i]*(m+1-i+1));
	sum:=sum+dis[1]*m;
        sum:=sum+m-1;
	writeln(sum);
end.