Untitled
unknown
plain_text
22 days ago
989 B
2
Indexable
Never
#include <bits/stdc++.h> using namespace std ; #define int long long #define For(n) for(int i = 0; i < n; i++) #define endl '\n' #define ld long double int n,k; bool can (ld arr[],ld mid,int n,int k){ priority_queue<ld,vector<ld>>pq; For(n)pq.push(arr[i]); while (k--&&!pq.empty()) { ld tmp = pq.top();pq.pop(); pq.push(tmp-mid);pq.push(mid); } // cout << mid << ' '<< pq.top()<<endl; return pq.top() <= mid; } void solve (){ int n,k;cin>>n>>k; ld arr[n]; For(n)cin>>arr[i]; sort(arr,arr+n); ld l =1,r=arr[n-1]; ld ans = arr[n-1]; int cnt = 10e3; while (l<=r&&cnt--){ ld mid = (r+l)/2; if(can(arr,mid,n,k)){ ans = mid; r=mid; } else l =mid; } cout << round(ans) << endl; } signed main () { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t =1; // cin>>t; while (t--){ solve(); } }
Leave a Comment