c++(0ms) linear solution
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
  int minimumSum(vector<int>& nums) {
    int ans = INT_MAX, n = nums.size();
    vector<int> l(n), r(n);
    l[0] = nums[0];
    for(int i = 1; i != n; ++i) l[i] = min(l[i-1], nums[i]);

    r.back() = nums.back();
    for(int i = n-2; i ; --i) r[i] = min(r[i+1], nums[i]);

    for(int i = nums.size() - 2; i; --i)
      if(nums[i] > r[i+1] && nums[i] > l[i-1])
        ans = min(ans, nums[i] + r[i+1] + l[i-1]);

    return ans == INT_MAX ? -1 : ans;      
  }
};
```
['C++']