Advertisement
cAbhi15

Untitled

Apr 1st, 2023
915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | Source Code | 0 0
  1. int findMaxCluster(vector<int> processingPower, vector<int> bootingPower, long powerMax) {
  2.     int n = processingPower.size();
  3.     int i = 0;
  4.     int j = 0;
  5.     deque<int> q;
  6.     long sum = 0;
  7.     int ans = 0;
  8.     while(j < n){
  9.         sum += processingPower[j];
  10.         while(!q.empty() && bootingPower[q.back()] <= bootingPower[j]){
  11.             q.pop_back();
  12.         }
  13.         q.push_back(j);
  14.  
  15.         while(i <= j and bootingPower[q.front()] + sum*(j-i+1) > powerMax){
  16.             if (q.front() == i){
  17.                 q.pop_front();
  18.             }
  19.             sum -= processingPower[i];
  20.             i++;
  21.         }
  22.         ans = max(ans, j-i+1);
  23.         j++;
  24.    
  25.     }
  26.  
  27.     return ans;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement