Guest User

Untitled

a guest
Jan 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1.  
  2. var
  3. a, f, t : array [0..5111] of longint;
  4. res,h,n,i,j : longint;
  5. begin
  6. assign(input, 'horses.in');
  7. assign(output, 'horses.out');
  8. reset(input);
  9. rewrite(output);
  10.  
  11. readln(n);
  12. for i:=1 to n do read(a[i]);
  13. fillchar(f, sizeof(f), 63);
  14. fillchar(t, sizeof(t), 63);
  15. f[1]:=1;
  16. t[1]:=0;
  17. for i:=1 to n do if f[i] <= a[i] then
  18. begin
  19. for j:=i+1 to n do if (a[j] >= a[i]+(j-i) * (j-i+1) shr 1)and(t[i] + 1 < t[j]) then
  20. begin
  21. f[j]:=a[i]+(j-i) * (j-i+1) shr 1;
  22. t[j]:=t[i] + 1;
  23. end;
  24. h:=a[i]+(n-i+1) * (n-i+2) shr 1;
  25. if (f[n+1] > h)or((f[n+1] = h)and(t[n+1] > t[i] + 1)) then
  26. begin
  27. f[n+1]:=h;
  28. t[n+1]:=t[i] + 1;
  29. end;
  30. end;
  31.  
  32. writeln(f[n+1],' ',t[n+1]-1);
  33. end.
Add Comment
Please, Sign In to add comment