Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int n; cin>>n;
- vector<int> a(n);
- for(int i=0;i<n;i++) cin>>a[i];
- // General format for most of 2 pointer prob
- for(int L=0,R=0;L<n;L++){
- // R is the index which can't be in our range
- R = L; // we should do this naively but for O(N) comp we will do
- R = max(R,L);
- while(we_can_include_R_in_current_range){
- include it
- R++;
- }
- // Now L....R-1 is the max range satisfying
- // condition for this fixed L
- // take max or count something as per ques.....
- // Now we will shift L and find the best R for L+1
- // But our main goal is to retain the info for L+1...R-1
- // which we have computed right now
- if(we_have_L_included_in_our_range(means R>L)) {
- remove L from the current range means
- basically remove from the aggregate info in which we are interested
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement