Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const double eps = 1e-9;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- int t;
- cin >> t;
- while(t--)
- {
- int n, k;
- cin >> n >> k;
- vector<int> arr(n);
- for(int &x : arr)
- cin >> x;
- double perc = double(k) / 100.0;
- double lo = 0, hi = 1e6, ans = 0;
- for(int itr = 0; itr < 100; itr++)
- {
- double mid = (lo + hi) / 2;
- double need = 0, have = 0;
- for(int i = 0; i < n; i++)
- {
- if(arr[i] > mid)
- have += arr[i] - mid;
- else
- need += (mid - arr[i]) / (1 - perc);
- }
- if(need <= have)
- ans = lo = mid;
- else
- hi = mid;
- }
- cout << setprecision(10) << fixed << ans << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment