Anyone did using single DP function call then updating for every queries.?I tried but not able to do
This doesn\'t work but If yours is working please send comment I need for reference\nThis is my Logic:\nThe st set keeps track of the indices that are part of t
# This doesn\'t work but If yours is working please send comment I need for reference\n*This is my Logic:\nThe st set keeps track of the indices that are part of the maximum sum subsequence.\nIn the maxSumFrom function, whenever the "take" option is chosen (i.e., take > notTake), the current index is inserted into st.\n\n*For each query, the corresponding element in nums is updated, and the memoization from the position of change onwards is invalidated.\nThe totalSum is recalculated using the maxSumFrom function, which updates the st set accordingly.\nThe results of each query are accumulated in ans.*\n\n```\n#define ll long long\n\nclass Solution {\n    private:\n    const int MOD = 1e9 + 7;\n    unordered_set<int> st;\nlong long maxSumFrom(int index, vector<int>& nums, int n, vector<long long>& memo) {\n        if (index >= n) return 0; \n        if (memo[index] != -1) return memo[index];  \n\n        \n        long long take = nums[index] + maxSumFrom(index + 2, nums, n, memo);\n        long long notTake = maxSumFrom(index + 1, nums, n, memo);\n\n        if (take > notTake) {\n            memo[index] = take;\n            st.insert(index);  \n        } else {\n            memo[index] = notTake;\n        }\n\n        return memo[index];\n    }\n    \n    \n    \npublic:\n    int maximumSumSubsequence(vector<int>& nums, vector<vector<int>>& queries) {\n        \n         ll n = nums.size();\n        vector<long long> memo(n+1,-1);\n        ll ans=0;\n    ll totalSum = maxSumFrom(0,nums,n,memo);\n        \n        // cout<<totalSum<<endl;\n        for(auto it: st){\n            cout<<it<<" ";\n        }\n        cout<<endl;\n    \n    for (auto& query : queries) {\n        ll pos = query[0];\n        ll val = query[1];\n        \n        if(st.find(pos)!=st.end()){\n            if(val> nums[pos]){\n            totalSum-=nums[pos];\n            totalSum+=val;\n               \n        }\n        else if(val>=0 && val < nums[pos]){\n            totalSum-=nums[pos];\n            totalSum+=val;\n             st.insert(pos);\n        }\n        else if(val < 0){\n            totalSum-=nums[pos];\n            st.erase(pos);\n        } \n            cout<<totalSum<<endl;\n        }\n        \n        // set m nhi hai\n        else{\n            if(val>=0 && st.find(pos-1)==st.end() && st.find(pos+1)==st.end() ){\n                totalSum+=val;\n                st.insert(pos);\n                nums[pos]=val;\n            }\n            else{\n                if(  st.find(pos-1)!=st.end() && st.find(pos+1)!=st.end()){\n                    if(nums[pos-1] + nums[pos+1] < val){\n                        totalSum-=(nums[pos-1] + nums[pos+1]);\n                        totalSum+=val;\n                        st.erase(pos-1);\n                        st.erase(pos+1);\n                        st.insert(pos);\n                    }\n                }\n                else if(st.find(pos-1)!=st.end()){\n                    \n                    if(nums[pos-1]  < val){\n                        totalSum-=(nums[pos-1]);\n                        totalSum+=val;\n                        st.erase(pos-1);\n                        st.insert(pos);\n                    }\n                }\n                else if (st.find(pos+1)!=st.end()){\n                    if(nums[pos+1]  < val){\n                        totalSum-=(nums[pos+1]);\n                        totalSum+=val;\n                        st.erase(pos+1);\n                        st.insert(pos);\n                    }\n                }\n                // nums[pos]=val;\n            }\n            cout<<totalSum<<endl;\n        }\n        // cout<<totalSum<<endl;\n        ans=( ans+ totalSum)%MOD;\n        nums[pos] = val;\n        \n        \n        \n    }\n    \n    return ans;\n    }\n};\n\n\n```
[]