比赛 |
NOIP2008集训模拟3 |
评测结果 |
C |
题目名称 |
工作分配 |
最终得分 |
0 |
用户昵称 |
SMXX |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-12 11:26:17 |
显示代码纯文本
program df;
var
a:array[1..100000]of longint;
f:array[1..100000,1..100000]of longint;
m:array[1..100000,0..1]of longint;
n,k,c,w,i,j,g,h:longint;
procedure qsort(g,h:longint);
var
n,m,u,x:longint;
begin
n:=g;m:=h;u:=a[(n+m)div 2] ;
repeat
while a[n]<u do inc(n);
while a[m]>u do dec(m);
if n<=m then begin
x:=a[n];
a[n]:=a[m];
a[m]:=x; inc(n);dec(m);
end;
until n>m;
if n<h then qsort(n,h);
if m>g then qsort(g,m);
end;
begin
readln(n,k,c);
for i:=1to n do read(a[i]);
qsort(1,n);
for i:= 1 to n div k do f[1,i]:=c;
for i:= 1to n do f[i,1]:=c+(a[i]-a[1])*(a[i]-a[i]);
for i:= 1to n do begin m[i,1]:=-1;m[i,0]:=-1;end;
for i:= 1 to n do begin
for j:= 1 to n div k-1 do begin
for h:= 1to j do begin
w:=100000000;
if (m[h,0]>0)and(m[h,1]>0) then
if (a[i]>m[h,0])and(a[i]<m[h,1])then w:=0
else begin
if (a[i]>m[h,1])and((a[i]-m[h,0])*(a[i]-m[h,0])-(m[h,1]-m[h,0])*(m[h,1]-m[h,0])<w)then begin
w:=(a[i]-m[h,0])*(a[i]-m[h,0])-(m[h,1]-m[h,0])*(m[h,1]-m[h,0]); g:=h ;end;
if (a[i]<m[h,0])and((m[h,1]-a[i])*(m[h,1]-a[i])-(m[h,1]-m[h,0])*(m[h,1]-m[h,0])<w) then begin g:=h;
W:=(m[h,1]-a[i])*(m[h,1]-a[i])-(m[h,1]-m[h,0])*(m[h,1]-m[h,0]);end;
end;
if w<>0 then begin if a[i]>m[g,1] then m[g,1]:=a[i];
if a[i]<m[g,0] then m[g,0]:=a[i];
end;
f[i,j]:=f[i-1,j]+w;
if f[i,j]>F[i-1,j-1]+c then begin m[j,1]:=a[i];m[j,0]:=a[i];end;
end;
end;
end;
end.
end.