{
ID:1011mashuo
PROG:barn1
LANG:PASCAL
}
program barn1;
type
atp=array[1..200] of longint;
var
n,s,c:longint;
a,b,d,e:atp;
procedure init;
var
i:longint;
begin
readln(n,s,c);
for i:=1 to c do read(a[i]);
if c<n then
begin
writeln(c);
halt;
end;
end;
procedure qsort(l,r:longint);
var
i,j,m,t:longint;
begin
i:=l;
j:=r;
m:=a[(l+r) shr 1];
repeat
while a[i]<m do inc(i);
while a[j]>m do dec(j);
if i<=j then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if i<r then qsort(i,r);
if l<j then qsort(l,j);
end;
procedure qsort1(l,r:longint);
var
i,j,m,t:longint;
begin
i:=l;
j:=r;
m:=b[(l+r) shr 1];
repeat
while b[i]<m do inc(i);
while b[j]>m do dec(j);
if i<=j then
begin
t:=b[i];
b[i]:=b[j];
b[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if i<r then qsort1(i,r);
if l<j then qsort1(l,j);
end;
procedure print;
var
i,q,tot,j,temp,t1,t2:longint;
begin
for i:=1 to c-1 do
begin
b[i]:=abs(a[i+1]-a[i]);
d[i]:=b[i];
end;
qsort1(1,c-1);
t1:=0;
temp:=0;
q:=c-1;
for i:=1 to n-1 do
begin
e[i]:=b[q];
dec(q);
end;
if n=1 then
begin
writeln(a[c]-a[1]+1);
halt;
end
else
begin
temp:=a[c]-a[1]+1;
for i:=1 to n-1 do temp:=temp-e[i]+1;
t1:=temp;
end;
writeln(t1);
end;
begin
assign(input,'barn1.in'); reset(input);
assign(output,'barn1.out'); rewrite(output);
init;
qsort(1,c);
print;
close(input); close(output);
end.
Barn Repair (barn1)[USACO 1.3.2]
最新推荐文章于 2024-04-30 21:53:33 发布