c++ dp
\nclass Solution {\npublic:\n    vector<int>v;\n    int n;\n    long long dp[100001][2][2];\n    long long fn(int ind,int st,int o){\n        if(ind>=n) return 
```\nclass Solution {\npublic:\n    vector<int>v;\n    int n;\n    long long dp[100001][2][2];\n    long long fn(int ind,int st,int o){\n        if(ind>=n) return 0;\n        if(dp[ind][st][o]!=-1) return dp[ind][st][o];\n        long long x;\n        if(st) x=v[ind]+max(fn(ind+1,0,1),fn(ind+1,1,0));\n        else{\n            if(o) x=-v[ind]+max(fn(ind+1,0,0),fn(ind+1,1,0));\n            else x=v[ind]+max(fn(ind+1,0,1),fn(ind+1,1,0));\n        }\n        return dp[ind][st][o]=x;\n    }\n    long long maximumTotalCost(vector<int>&vp) {\n        v=vp;\n        n=v.size();\n        memset(dp,-1,sizeof(dp));\n        return fn(0,1,0);\n    }\n};\n```
['Dynamic Programming', 'C']