Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- int n, h;
- cin>>n>>h;
- vector<int> a(n);
- for(auto &e: a) cin>>e;
- int ans=0, low=0, high=1e9;
- auto check = [&](int x)
- {
- int tmp = h;
- for(auto e: a)
- {
- if(e <= x) continue;
- tmp -= e;
- if(tmp <= 0) return 0;
- }
- return 1;
- };
- while(low <= high)
- {
- int mid = (low + high)/2;
- if(check(mid))
- ans=mid, high=mid-1;
- else
- low=mid+1;
- }
- cout<<ans<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement