fork download
  1. // وَمَا تَوْفِيقِي إِلَّا بِاللَّهِ عَلَيْهِ تَوَكَّلْتُ وَإِلَيْهِ أُنِيبُ
  2.  
  3. #include <bits/stdc++.h>
  4. #define T int t;cin>>t;while(t--)
  5. #define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
  6. #define ll long long
  7. #define endl '\n'
  8. #define int ll
  9. using namespace std;
  10.  
  11. void Abady() {
  12. T {
  13. int n, d, x;
  14. cin >> n >> d >> x;
  15. int arr[n];
  16. for (int i = 0; i < n; i++) {
  17. cin >> arr[i];
  18. }
  19. sort(arr, arr + n);
  20. reverse(arr, arr + n);
  21. int l = 1, r = 1e18, ans = (-1);
  22. while (l <= r) {
  23. int mid = (l + r) / 2;
  24. int k = 0;
  25. bool j = 0;
  26. multiset<double> st;
  27. for (int i=0;i<n;i++) {
  28. double e = (double)arr[i]/(double)mid;
  29. if (e>x) {
  30. j=1;
  31. break;
  32. }
  33. if (st.size()) {
  34. auto m = st.lower_bound(e);
  35. if (m != st.end()) {
  36. st.erase(m);
  37. continue;
  38. }
  39. }
  40. if (e<x) {
  41. st.insert((double)x-(double)e);
  42. }
  43. k++;
  44. }
  45. if (j || (k>d)) l = mid + 1;
  46. else {
  47. ans = mid;
  48. r = mid - 1;
  49. }
  50. }
  51. cout << ans << endl;
  52. }
  53. }
  54.  
  55. signed main() {
  56. fast;
  57. Abady();
  58. }
  59.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty