Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <set>
- #include <stack>
- #include <queue>
- using namespace std;
- #define MOD 1000000007
- #define MOD1 998244353
- #define rep(i,b) for(int i = 0; i < b; i++)
- #define nl "\n"
- #define sp " "
- #define inf 1000000004
- #define minf INT_MIN
- #define pb push_back
- #define vi vector<int>
- #define sz(x) ((int)(x).size())
- #define all(x) (x).begin(), (x).end()
- #define ys cout << "YES" << nl
- #define no cout << "NO" << nl
- #define ll long long
- #define int long long
- template<typename T> istream& operator>>(istream& is, vector<T> &v){for (auto& i : v) is >> i; return is;}
- template<typename T> ostream& operator<<(ostream& os, vector<T> v){for (auto& i : v) os << i << ' '; return os;}
- 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;}
- int n , h;
- bool helper(vector<int>& v , int k){
- int sum = 0;
- for(int i = 0; i < n - 1; i++){
- sum += min((v[i + 1] - v[i]) , k) + 1;
- }
- sum += (k - 1);
- return sum > h;
- }
- void solve(){
- cin >> n >> h;
- vi v(n); cin >> v;
- int low = 1, high = 1e18 , ans = 0;
- while(low <= high){
- int mid = low + (high - low) / 2;
- if(helper(v , mid)){
- ans = mid;
- high = mid - 1;
- }
- else low = mid + 1;
- }
- cout << ans << nl;
- }
- int32_t main(){
- ios_base::sync_with_stdio(0);cin.tie(0);
- int t = 1;
- cin >> t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement