C++ | Priority Queue + DP
\nclass Solution {\npublic:\n    int maxResult(vector<int>& nums, int k) {\n        priority_queue<pair<int,int>> dq;\n        int n = nums.size();\n        vec
```\nclass Solution {\npublic:\n    int maxResult(vector<int>& nums, int k) {\n        priority_queue<pair<int,int>> dq;\n        int n = nums.size();\n        vector<int> dp(n+5,0);\n        for(int i=0 ; i<n ; i++){\n            if(dq.empty()){\n                dq.push(make_pair(nums[i],i));\n                dp[i] = nums[i];\n            }\n            else{\n                while(dq.top().second<(i-k)){\n                    dq.pop();\n                }\n                dp[i] = dq.top().first+nums[i];\n                dq.push(make_pair(dp[i],i));\n            }\n            cout << dp[i] << endl;\n        }\n        return dp[n-1];\n    }\n};\n```
[]