SHARE
TWEET

COWS

a guest Jul 22nd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program zad_k;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.     SysUtils;
  7.  
  8. const
  9.     MAXN = 11000;
  10.  
  11. var
  12.     a: array [0..MAXN] of integer;
  13.     k, r, l, b, c, j, n, i, m: integer;
  14.  
  15. function f(m: integer): integer;
  16. var
  17.     i, b, c: integer;
  18. begin
  19.     b := 1;
  20.     c := 1;
  21.     for i := 2 to n do
  22.         if (a[i] - a[c] >= m) then begin
  23.             c := i;
  24.             inc(b);
  25.         end;
  26.     f := b;
  27. end;
  28.  
  29. begin
  30.     readln(n, k);
  31.     for i := 1 to n do
  32.         read(a[i]);
  33.     readln;
  34.    
  35.     if (k = 2) or (n = 3) then begin
  36.         writeln(a[n] - a[1]);
  37.         exit;
  38.     end;
  39.     r := a[n] - a[1];
  40.     l := 0;
  41.     while (r <> l) do begin
  42.         m := (l + r) div 2;
  43.         if (f(m) >= k) then
  44.             l := m + 1
  45.         else
  46.             r := m;
  47.     end;
  48.     writeln(l - 1);
  49.     readln;
  50. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top