Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int findMaxCluster(vector<int> processingPower, vector<int> bootingPower, long powerMax) {
- int n = processingPower.size();
- int i = 0;
- int j = 0;
- deque<int> q;
- long sum = 0;
- int ans = 0;
- while(j < n){
- sum += processingPower[j];
- while(!q.empty() && bootingPower[q.back()] <= bootingPower[j]){
- q.pop_back();
- }
- q.push_back(j);
- while(i <= j and bootingPower[q.front()] + sum*(j-i+1) > powerMax){
- if (q.front() == i){
- q.pop_front();
- }
- sum -= processingPower[i];
- i++;
- }
- ans = max(ans, j-i+1);
- j++;
- }
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement