5 Lines of code: simple DP with constant space. 0ms, beats 100%
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nimpl Solution {\n    pub fn maximum_total_cost(nums: Vec<i32>) -> i64 {     \n   
# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nimpl Solution {\n    pub fn maximum_total_cost(nums: Vec<i32>) -> i64 {     \n        let (mut dp0, mut dp1) = (nums[0] as i64,nums[0] as i64);\n        for idx in 1..nums.len() {\n            (dp0, dp1) = (dp0.max(dp1) + nums[idx] as i64,dp0 - nums[idx] as i64);            \n        }\n        dp0.max(dp1)        \n    }\n}\n```
['Rust']