fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6. inline int power(int a, int b) {
  7. int x = 1;
  8. while (b) {
  9. if (b & 1) x *= a;
  10. a *= a;
  11. b >>= 1;
  12. }
  13. return x;
  14. }
  15.  
  16.  
  17. const int M = 1000000007;
  18. const int N = 3e5+9;
  19. const int INF = 2e9+1;
  20. const int LINF = 2000000000000000001;
  21.  
  22. //_ ***************************** START Below *******************************
  23.  
  24.  
  25.  
  26.  
  27. vector<int> a;
  28. vector<int> b;
  29.  
  30. bool isPossible(int n, int k, double mid){
  31. vector<double> t(n);
  32. for(int i=0; i<n; i++){
  33. t[i] = a[i] - b[i]*mid;
  34. }
  35.  
  36. sort(begin(t), end(t), greater<double>());
  37.  
  38. double sum = 0;
  39. for(int i=0; i<k; i++){
  40. sum += t[i];
  41. }
  42.  
  43. return sum >= 0;
  44.  
  45. }
  46.  
  47. double consistency(int n, int k){
  48.  
  49. double s = 0;
  50. double e = INF;
  51.  
  52. for(int i=0; i<100; i++){
  53. double mid = s + (e-s)/2;
  54. if(isPossible(n, k, mid)){
  55. s = mid;
  56. }
  57. else e = mid;
  58. }
  59.  
  60. return e;
  61.  
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. double practice(int n, int d){
  81.  
  82. return 0;
  83.  
  84. }
  85.  
  86.  
  87.  
  88.  
  89.  
  90. void solve() {
  91.  
  92. int n, k;
  93. cin>> n >> k;
  94. a.resize(n);
  95. b.resize(n);
  96.  
  97. for(int i=0; i<n; i++){
  98. cin >> a[i];
  99. cin >> b[i];
  100. }
  101.  
  102. cout << fixed << setprecision(7) << consistency(n, k) << endl;
  103.  
  104. // cout << fixed << setprecision(7) << consistency(n, k) << " -> " << practice(n, k) << endl;
  105.  
  106.  
  107.  
  108. }
  109.  
  110.  
  111.  
  112.  
  113.  
  114. int32_t main() {
  115. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  116.  
  117. int t = 1;
  118. while (t--) {
  119. solve();
  120. }
  121.  
  122. return 0;
  123. }
  124.  
  125.  
Success #stdin #stdout 0.01s 5284KB
stdin
8 3
4 2
4 2
2 2
1 5
5 3
3 5
2 2
5 3
stdout
1.8571429