Guest User

Untitled

a guest
Mar 10th, 2016
4,026
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include <cstring>
  2. #include <vector>
  3. #include <list>
  4. #include <map>
  5. #include <set>
  6. #include <deque>
  7. #include <stack>
  8. #include <bitset>
  9. #include <algorithm>
  10. #include <functional>
  11. #include <numeric>
  12. #include <utility>
  13. #include <sstream>
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cstdio>
  17. #include <cmath>
  18. #include <queue>
  19. #include <cstdlib>
  20. #include <ctime>
  21. #include <cassert>
  22.  
  23. #define pii pair<ld, ld>
  24.  
  25. #define pb push_back
  26. #define mp make_pair
  27.  
  28. #define x first
  29. #define y second
  30.  
  31. using namespace std;
  32.  
  33. typedef unsigned long long ull;
  34. typedef long long ll;
  35. typedef long double ld;
  36.  
  37. const int MXN = 1e5 * 2 + 1;
  38. const int TMXN = 1e5 * 8 + 1;
  39. const int INF = 1e9 + 7;
  40. const ll INFL = 1e18;
  41.  
  42. ll n, m, t[TMXN], l, r, d[TMXN], res, c, maxk, ind = 1, ans, k;
  43. ll a[MXN], two = 1, b[MXN];
  44. bool chec(int x){
  45. for(int i = 2; i <= n; i++){
  46. if(a[i] - a[ind] >= x){
  47. ind = i;
  48. ans ++;
  49. }
  50. }
  51. if(ans >= k){
  52. return true;
  53. }
  54. else{
  55. return false;
  56. }
  57. }
  58. int main(){
  59. freopen("cows.in", "r", stdin);
  60. freopen("cows.out", "w", stdout);
  61. cin >> n >> k;
  62. for(int i = 1; i <= n; i++){
  63. cin >> a[i];
  64. }
  65. l = 0;
  66. r = INF;
  67. while(r - l > 1){
  68. ll mid = (l + r) / 2;
  69. ind = 1;
  70. ans = 1;
  71. if(chec(mid)){
  72. l = mid;
  73. maxk = max(maxk, mid);
  74. }
  75. else{
  76. r = mid;
  77. }
  78. }
  79. cout << maxk;
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment