4 lines Java Easy
Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n2) \n\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO(n2) + 
# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n*2)$$ \n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n*2) + (Stack  Space- O(n))$$\n\n# Code\n```\nclass Solution {\n    public long maximumTotalCost(int[] nums) {\n        t=new Long[nums.length][2];\n        return rec(0,1,nums);\n    }\n    Long[][] t;\n    public long rec(int i,int f,int[] arr){\n        if(i>=arr.length) return 0;\n        if(t[i][Math.max(f,0)]!=null) return t[i][Math.max(f,0)];\n        long take=f*arr[i]+rec(i+1,f*-1,arr);\n        long startnew=arr[i]+rec(i+1,-1,arr);\n        return t[i][Math.max(f,0)]=Math.max(take,startnew);\n    }\n}\n```
['Java']