fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define double long double
  4. signed main(){
  5. int n, k;
  6. cin >> n >> k;
  7. vector<int> a(n);
  8. for(int i = 0; i < n; i++){
  9. cin >> a[i];
  10. }
  11. double l = 1, r = 1e7;
  12. double ans = 0;
  13. for(int i = 0; i < 60; i++){
  14. double mid = (l + r) * 0.5;
  15. int now = 0;
  16. for(int j = 0; j < a.size(); j++){
  17. now += a[j] / mid;
  18. }
  19. cout << now << endl;
  20. if(now == k){
  21. l = mid;
  22. ans = max(ans, mid);
  23. }
  24. if(now > k){
  25. l = mid;
  26. }else{
  27. r = mid;
  28. }
  29.  
  30. }
  31. cout << fixed << setprecision(15) << ans;
  32. }
Success #stdin #stdout 0s 5292KB
stdin
4 11
802
743
457
539
stdout
0
0
0
0
0
0
0
0
0
0
0
0
0
2
6
14
9
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
11
191.734844207763672