Advertisement
vinayak7989

Shubhi

Sep 17th, 2021
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.       int n; cin>>n;
  6.       vector<int> a(n);
  7.       for(int i=0;i<n;i++) cin>>a[i];
  8.  
  9.       // General format for most of 2 pointer prob
  10.       for(int L=0,R=0;L<n;L++){
  11.             // R is the index which can't be in our range
  12.             R = L; // we should do this naively but for O(N) comp we will do
  13.             R = max(R,L);
  14.             while(we_can_include_R_in_current_range){
  15.                   include it
  16.                   R++;
  17.             }
  18.             // Now L....R-1 is the max range satisfying
  19.             // condition for this fixed L
  20.  
  21.             // take max or count something as per ques.....
  22.  
  23.             // Now we will shift L and find the best R for L+1
  24.             // But our main goal is to retain the info for L+1...R-1
  25.             // which we have computed right now
  26.  
  27.             if(we_have_L_included_in_our_range(means R>L)) {
  28.                   remove L from the current range means
  29.                   basically remove from the aggregate info in which we are interested
  30.             }
  31.       }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement