fork download
  1. //Believe in yourself ,( try and try and then try ), You can do it
  2. //You don't have to be great to start but you have to start to be great
  3. #include <iostream>
  4. #include<algorithm>
  5. #include<cmath>
  6. #include<string>
  7. #include<vector>
  8. #include <utility>
  9. #include <stack>
  10. #include <set>
  11. #include <map>
  12. #include<queue>
  13. #include<set>
  14. #include<iomanip>
  15. // 2D vector vector<vector<int>>v(n,vector<int>(m));
  16. // sort and reverse in vector sort(v.begin(), v.end(), greater<int>());
  17. // str.erase(pos,len); erase in string
  18. // a = s.substr(0, i)<<before i, b = s.substr(i)<<from i to end;
  19. // cout << (v[0] == 1 ? "YES" : "NO") << endl;
  20. // unsigned long long int
  21. // priority_queue<ll, vector<ll>, greater<ll>> p;
  22. using namespace std;
  23. #define ll long long
  24. #define all(c) c.begin(),c.end()
  25.  
  26.  
  27. ll gcd(ll a, ll b)
  28. {
  29. while (b != 0)
  30. {
  31. ll a2 = a;
  32. a = b; b = a2 % b;
  33. }
  34. return a;
  35. }
  36.  
  37. ll lcm(ll a, ll b)
  38. {
  39. return a / gcd(a, b) * b;
  40. }
  41.  
  42. void soso()
  43. {
  44. ios::sync_with_stdio(0);
  45. cin.tie(NULL);
  46. cout.tie(NULL);
  47. }
  48.  
  49. ll n; double k;
  50. double arr[200005];
  51. bool can(double mid)
  52. {
  53. double sum = 0, neg = 0;
  54. for(int i = 0; i < n; i++)
  55. {
  56. if (arr[i] > mid)
  57. {
  58. ll x = arr[i] - mid;
  59. sum += (x - ((x * k) / 100));
  60. }
  61. else if (arr[i] < mid)
  62. {
  63. neg+= (mid - arr[i]);
  64. }
  65. }
  66. return sum>=neg;
  67. }
  68. int main()
  69. {
  70. soso();
  71. cin >> n >> k;
  72. for (int i = 0; i < n; i++)cin >> arr[i];
  73. double l = 1, r = 10005, ans = 0;
  74. const double f = 1e-7;
  75. while (fabs(l - r) > f)
  76. {
  77.  
  78. double mid = (l + r) / 2.0;
  79. if (can(mid))
  80. {
  81. l = mid;
  82. ans = mid;
  83. }
  84. else r = mid;
  85. }
  86. cout << fixed<<setprecision(9) << ans;
  87.  
  88. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
10004.999999927