Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var
- a, f, t : array [0..5111] of longint;
- res,h,n,i,j : longint;
- begin
- assign(input, 'horses.in');
- assign(output, 'horses.out');
- reset(input);
- rewrite(output);
- readln(n);
- for i:=1 to n do read(a[i]);
- fillchar(f, sizeof(f), 63);
- fillchar(t, sizeof(t), 63);
- f[1]:=1;
- t[1]:=0;
- for i:=1 to n do if f[i] <= a[i] then
- begin
- 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
- begin
- f[j]:=a[i]+(j-i) * (j-i+1) shr 1;
- t[j]:=t[i] + 1;
- end;
- h:=a[i]+(n-i+1) * (n-i+2) shr 1;
- if (f[n+1] > h)or((f[n+1] = h)and(t[n+1] > t[i] + 1)) then
- begin
- f[n+1]:=h;
- t[n+1]:=t[i] + 1;
- end;
- end;
- writeln(f[n+1],' ',t[n+1]-1);
- end.
Add Comment
Please, Sign In to add comment