Language: C++

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<int> s(n, a[0]);
    for (int i = 1; i < n; i++) {
        s[i] = s[i-1] + a[i];
    }

    vector<int> f(n-2);
    int l = 0, r = 1;
    while (r < n-2) {
        while (l < n-3 && abs(s[r]-2*s[l]) > abs(s[r]-2*s[l+1])) {
            l++;
        }
        f[r] = l;
        r++;
    }

    vector<int> g(n-2);
    l = 1, r = 2;
    while (l < n-2) {
        while (r < n-1 && abs(s[n-1]-2*s[r]+s[l]) > abs(s[n-1]-2*s[r+1]+s[l])) {
            r++;
        }
        g[l] = r;
        l++;
    }

    vector<int> ans(n-2);
    for (int i = 1; i < n-2; i++){
        ans[i] = max({s[f[i]], s[i]-s[f[i]], s[g[i]]-s[i], s[n-1]-s[g[i]]})
            - min({s[f[i]], s[i]-s[f[i]], s[g[i]]-s[i], s[n-1]-s[g[i]]});
    }

    cout << *min_element(ans.begin()+1, ans.end()) << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:42:21: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   42 |         ans[i] = max({s[f[i]], s[i]-s[f[i]], s[g[i]]-s[i], s[n-1]-s[g[i]]})
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
a.cc:43:18: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   43 |             - min({s[f[i]], s[i]-s[f[i]], s[g[i]]-s[i], s[n-1]-s[g[i]]});
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
a.cc:46:14: error: 'min_element' was not declared in this scope
   46 |     cout << *min_element(ans.begin()+1, ans.end()) << endl;
      |              ^~~~~~~~~~~