Advertisement
pratiyush7

Untitled

Nov 23rd, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. string ltrim(const string &);
  6. string rtrim(const string &);
  7.  
  8.  
  9. /*
  10. * Complete the 'maximumClusterQuality' function below.
  11. *
  12. * The function is expected to return a LONG_INTEGER.
  13. * The function accepts following parameters:
  14. * 1. INTEGER_ARRAY speed
  15. * 2. INTEGER_ARRAY reliability
  16. * 3. INTEGER maxMachines
  17. */
  18. #define ll long long int
  19.  
  20. long maximumClusterQuality(vector<int> s, vector<int> r, int m) {
  21. vector<pair<ll,ll>> v;
  22. int n = s.size();
  23. for(int i=0;i<n;i++)
  24. {
  25. v.push_back({r[i],s[i]});
  26. }
  27. sort(v.begin(),v.end());
  28. reverse(v.begin(),v.end());
  29. ll sum = 0;
  30. multiset<ll> sm;
  31. for(int i=0;i<m;i++)
  32. {
  33. sm.insert(v[i].second);
  34. sum+=v[i].second;
  35. }
  36. ll ans = (v[m-1].first * sum);
  37. for(int i=m;i<n;i++)
  38. {
  39. auto it = sm.begin();
  40. ll x = (*it);
  41. if((x) < v[m].second)
  42. {
  43. sum-=(x);
  44. sm.erase(sm.find(x));
  45. sm.insert(v[m].second);
  46. sum+=v[m].second;
  47. }
  48. ans = max(ans,sum*v[m].first);
  49. }
  50. return ans;
  51. }
  52. int main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement