Advertisement
haufont

Untitled

Jun 13th, 2016
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<set>
  4. #include<math.h>
  5. using namespace std;
  6. int A[1000];
  7. long long f(int a,int b)
  8. {
  9. long long min = 999999;
  10. long long m=1;
  11. for (int i = 0; i < a-1; i++)
  12. {
  13. if (abs(A[i + 1] - A[i]) >= b)
  14. {
  15. m++;
  16. }
  17. }
  18. return m;
  19. }
  20. int main()
  21. {
  22. long long a,b;
  23. cin >> a>>b;
  24. for (int i = 0; i < a; i++)
  25. {
  26. cin >> A[i];
  27. }
  28. long long l = 0;
  29. long long r = 10000000000;
  30. int m;
  31. while ((l + 1) < r)
  32. {
  33. m = (l + r) / 2;
  34. if (f(a, m) >= b)
  35. {
  36. l = m;
  37. }
  38. else
  39. {
  40. r = m;
  41. }
  42. }
  43. cout << r;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement