fork download
  1. #include <bits/stdc++.h>
  2. #define FIO ios_base::sync_with_stdio(0); cin.tie(0);
  3. #define pb push_back
  4. #define x first
  5. #define y second
  6. using namespace std;
  7. typedef long long ll;
  8. const long long N = 1e5 + 5, N1 = 2e5 + 5, MOD = 1e9 + 7, HS = 31, HS2 = 47, M2 = 1e9 + 9;
  9. const ll OO = 1e9;
  10. const double EPS = 1e-9;
  11. const double PI = acos(-1);
  12.  
  13.  
  14. int n, k, num;
  15. double a[N];
  16.  
  17.  
  18. bool valid(double num){
  19. int cnt=0;
  20.  
  21. for(int i = 0; i < n; ++i){
  22. cnt += a[i]/num;
  23. }
  24.  
  25. return cnt >= k;
  26. }
  27.  
  28.  
  29. double bs(){
  30. double l=1e-7, m, h=2e7+1;
  31.  
  32. for(int i = 0; i < 50; ++i){
  33. m = (h+l)/2;
  34. if(valid(m)) l = m;
  35. else h = m;
  36. }
  37.  
  38. return l;
  39. }
  40.  
  41.  
  42. int main(){
  43. FIO
  44. cin >> n >> k;
  45.  
  46. for(int i = 0; i < n; ++i) cin >> a[i];
  47.  
  48. cout.precision(6);
  49. cout << fixed << bs() << "\n";
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
20000001.000000