记录编号 38820 评测结果 AAAAAAAAAA
题目名称 工作指派 最终得分 100
用户昵称 Gravatarwo shi 刘畅 是否通过 通过
代码语言 Pascal 运行时间 1.132 s
提交时间 2012-06-14 20:57:59 内存使用 1.69 MiB
显示代码纯文本
  1. const
  2. maxn=100000000000000000;
  3.  
  4. var
  5. i,j:longint;
  6. n,k,c,max,min:int64;
  7. a,f:Array[0..100000]of int64;
  8.  
  9. procedure sort(l,r:longint);
  10. var
  11. i,j,x,y:longint;
  12. begin
  13. x:=a[(l+r) div 2];
  14. i:=l;
  15. j:=r;
  16. repeat
  17. while a[i]<x do inc(i);
  18. while x<a[j] do dec(j);
  19. if i<=j then
  20. begin
  21. y:=a[i];
  22. a[i]:=a[j];
  23. a[j]:=y;
  24. inc(i);
  25. dec(j);
  26. end;
  27. until i>j;
  28. if i<r then sort(i,r);
  29. if l<j then sort(l,j);
  30. end;
  31.  
  32.  
  33. begin
  34. assign(input,'dividea.in'); reset(input);
  35. assign(output,'dividea.out'); rewrite(output);
  36. readln(n,k,c);
  37. for i:=1 to n do read(a[i]);
  38. sort(1,n);
  39. f[1]:=c;
  40. for i:=2 to n do
  41. begin
  42. f[i]:=maxn;
  43. for j:=i-k+1 downto 1 do
  44. begin
  45. if f[j-1]+c+sqr(a[i]-a[j])<f[i] then f[i]:=f[j-1]+c+sqr(a[i]-a[j]);
  46. end;
  47. end;
  48. writeln(f[n]);
  49. close(input);
  50. close(output);
  51. end.