Advertisement
newb_ie

monkey and the oiled bamboo

Aug 29th, 2021
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int maxN = 1e5;
  5. int a[maxN];
  6.  
  7. bool f (int k,int n) {
  8. for (int i = 1; i <= n; ++i) {
  9. if (a[i] - a[i - 1] > k) return false;
  10. if (a[i] - a[i - 1] == k) --k;
  11. }
  12. return true;
  13. }
  14.  
  15. int main () {
  16. ios::sync_with_stdio(false);
  17. cin.tie(nullptr);
  18. cout.tie(nullptr);
  19. int T;
  20. cin >> T;
  21. for (int test_case = 1; test_case <= T; ++test_case) {
  22. int n;
  23. cin >> n;
  24. for (int i = 1; i <= n; ++i) cin >> a[i];
  25. a[0] = 0;
  26. int l = a[1],r = 1e8;
  27. int res = 0;
  28. while (l <= r) {
  29. int mid = (l + r) / 2;
  30. if (f(mid,n)) {
  31. res = mid;
  32. r = mid - 1;
  33. } else {
  34. l = mid + 1;
  35. }
  36. }
  37. cout << "Case " << test_case << ": " << res << '\n';
  38. }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement