Advertisement
enigmjoe

help

Jul 1st, 2023 (edited)
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <map>
  6. #include <set>
  7. #include <stack>
  8. #include <queue>
  9.  
  10. using namespace std;
  11.  
  12. #define MOD 1000000007
  13. #define MOD1 998244353
  14. #define rep(i,b) for(int i = 0; i < b; i++)
  15. #define nl "\n"
  16. #define sp " "
  17. #define inf 1000000004
  18. #define minf INT_MIN
  19. #define pb push_back
  20. #define vi vector<int>
  21. #define sz(x) ((int)(x).size())
  22. #define all(x) (x).begin(), (x).end()
  23. #define ys cout << "YES" << nl
  24. #define no cout << "NO" << nl
  25. #define ll long long
  26. #define int long long
  27. template<typename T> istream& operator>>(istream& is, vector<T> &v){for (auto& i : v) is >> i; return is;}
  28. template<typename T> ostream& operator<<(ostream& os, vector<T> v){for (auto& i : v) os << i << ' '; return os;}
  29. vector<int> suffix(vector<int> arr){int n = sz(arr); vector<int> suffixSum(n, 0); suffixSum[n - 1] = arr[n - 1]; for (int i = n - 2; i >= 0; i--) suffixSum[i] = suffixSum[i + 1] + arr[i]; return suffixSum;}
  30.  
  31. int n , h;
  32.  
  33. bool helper(vector<int>& v , int k){
  34. int sum = 0;
  35. for(int i = 0; i < n - 1; i++){
  36. sum += min((v[i + 1] - v[i]) , k) + 1;
  37. }
  38. sum += (k - 1);
  39. return sum > h;
  40. }
  41.  
  42. void solve(){
  43. cin >> n >> h;
  44. vi v(n); cin >> v;
  45. int low = 1, high = 1e18 , ans = 0;
  46. while(low <= high){
  47. int mid = low + (high - low) / 2;
  48. if(helper(v , mid)){
  49. ans = mid;
  50. high = mid - 1;
  51. }
  52. else low = mid + 1;
  53. }
  54. cout << ans << nl;
  55. }
  56.  
  57. int32_t main(){
  58. ios_base::sync_with_stdio(0);cin.tie(0);
  59. int t = 1;
  60. cin >> t;
  61. while(t--){
  62. solve();
  63. }
  64. return 0;
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement