Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- string ltrim(const string &);
- string rtrim(const string &);
- /*
- * Complete the 'maximumClusterQuality' function below.
- *
- * The function is expected to return a LONG_INTEGER.
- * The function accepts following parameters:
- * 1. INTEGER_ARRAY speed
- * 2. INTEGER_ARRAY reliability
- * 3. INTEGER maxMachines
- */
- #define ll long long int
- long maximumClusterQuality(vector<int> s, vector<int> r, int m) {
- vector<pair<ll,ll>> v;
- int n = s.size();
- for(int i=0;i<n;i++)
- {
- v.push_back({r[i],s[i]});
- }
- sort(v.begin(),v.end());
- reverse(v.begin(),v.end());
- ll sum = 0;
- multiset<ll> sm;
- for(int i=0;i<m;i++)
- {
- sm.insert(v[i].second);
- sum+=v[i].second;
- }
- ll ans = (v[m-1].first * sum);
- for(int i=m;i<n;i++)
- {
- auto it = sm.begin();
- ll x = (*it);
- if((x) < v[m].second)
- {
- sum-=(x);
- sm.erase(sm.find(x));
- sm.insert(v[m].second);
- sum+=v[m].second;
- }
- ans = max(ans,sum*v[m].first);
- }
- return ans;
- }
- int main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement