sudama_bera

leetcode_problem

May 8th, 2026
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | Source Code | 0 0
  1.   int maxFixedPoints(vector<int>& nums) {
  2.         int n=nums.size();
  3.         vector<pair<int,int>>v;
  4.         for(int i=0;i<n;i++){
  5.             if(i>=nums[i]){
  6.                 v.push_back({nums[i],i-nums[i]});
  7.             }
  8.         }
  9.         sort(v.begin(),v.end(),[](const pair<int,int>&a,const pair<int,int>&b){
  10.             if(a.first!=b.first)return a.first<b.first;
  11.             return a.second>b.second;
  12.         });
  13.         vector<int>dp;
  14.         for(auto&[f,s]:v){
  15.             auto it=upper_bound(dp.begin(),dp.end(),s);
  16.             if(it==dp.end())dp.push_back(s);
  17.             else *it=s;
  18.         }
  19.         return dp.size();
  20.     }
  21.  
  22. for "https://leetcode.com/problems/maximize-fixed-points-after-deletions/"
Tags: C++ leetcode
Advertisement
Add Comment
Please, Sign In to add comment