pranavsindura

Problem P

Oct 6th, 2020
891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const double eps = 1e-9;
  5.  
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(NULL);
  10.     cout.tie(NULL);
  11.  
  12.     int t;
  13.     cin >> t;
  14.     while(t--)
  15.     {
  16.         int n, k;
  17.         cin >> n >> k;
  18.         vector<int> arr(n);
  19.         for(int &x : arr)
  20.             cin >> x;
  21.  
  22.         double perc = double(k) / 100.0;
  23.         double lo = 0, hi = 1e6, ans = 0;
  24.  
  25.         for(int itr = 0; itr < 100; itr++)
  26.         {
  27.             double mid = (lo + hi) / 2;
  28.             double need = 0, have = 0;
  29.             for(int i = 0; i < n; i++)
  30.             {
  31.                 if(arr[i] > mid)
  32.                     have += arr[i] - mid;
  33.                 else
  34.                     need += (mid - arr[i]) / (1 - perc);
  35.             }
  36.  
  37.             if(need <= have)
  38.                 ans = lo = mid;
  39.             else
  40.                 hi = mid;
  41.         }
  42.  
  43.         cout << setprecision(10) << fixed << ans << endl;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment