Untitled
#include<bits/stdc++.h> #define ll long long #define endl "\n" using namespace std; template<class T> void printff(vector<T>& v) { for (auto k : v) cout << k << " "; cout << endl; } int n; ll k; ll target; bool check(vector<ll> & a, ll mid){ ll sum = 0; for(int i = 0; i < n; i++){ sum += (a[i] / mid); if (sum >= target) return true; } return false; } void SOLVE() { cin >> n >> k; target = k * k; vector<ll> a(n); for(auto & val : a) cin >> val; ll l = 0, r = 1e10 + 1; while(r - l > 1){ ll mid = (l + r) >> 1LL; if(check(a, mid)) l = mid; else r = mid; } if(l == 0) cout << -1 << endl; else cout << l << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc = 1; cin >> tc; while(tc--) SOLVE(); return 0; }
Leave a Comment