Advertisement
Saleh127

Light oj(LO) 1280

Jan 21st, 2021
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. vector<pair<double,double>>m;
  6. double Mid;
  7.  
  8. bool compare(pair<double,double>a,pair<double,double>b)
  9. {
  10. if(a.first-Mid*a.second>b.first-Mid*b.second) return 1;
  11. else return 0;
  12. }
  13.  
  14. bool solve(double mid,ll sub)
  15. {
  16. Mid=mid/100.00;
  17. sort(m.begin(),m.end(),compare);
  18.  
  19. double p=0.0,t=0.0,res;
  20. for(ll i=0; i<sub; i++)
  21. {
  22. p+=m[i].first;
  23. t+=m[i].second;
  24. }
  25. res=(p*100.00)/t;
  26.  
  27. if(res>=mid) return 1;
  28. else return 0;
  29.  
  30. }
  31.  
  32. int main()
  33. {
  34. ios_base::sync_with_stdio(0);
  35. cin.tie(0);
  36. cout.tie(0);
  37.  
  38. test
  39. {
  40. ll n,d,i,j,k;
  41. cin>>n>>d;
  42.  
  43. m.clear();
  44.  
  45. for(i=0; i<n; i++)
  46. {
  47. pair<double,double>a;
  48. cin>>a.first>>a.second;
  49. m.push_back(a);
  50. }
  51.  
  52. double lo=0.0,hi=100.00,ans=0.0,mid;
  53.  
  54. while(hi-lo>0.0000001)
  55. {
  56. mid=(lo+hi)/2.0;
  57.  
  58. if(solve(mid,n-d))
  59. {
  60. ans=mid;
  61. lo=mid;
  62. }
  63. else hi=mid;
  64. }
  65.  
  66. cout<<"Case "<<cs<<": "<<setprecision(9)<<ans<<endl;
  67.  
  68. }
  69.  
  70.  
  71. return 0;
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement