Language: C++

#include <cstdio>
#include <iostream>
#include <vector>
#include <cassert>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <cstdlib>
#include <string>
#include <unordered_map>
#include <map>
#include <sstream>
#include <bitset>
#include <random>
#include <tuple>
#include <array>
#include <tgmath.h>
#include <functional>
#include <climits>
#include <complex>
#include <unistd.h>
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> plli;
typedef unsigned char byte;
typedef unsigned int uint;
typedef unsigned long long int ulli;

lli arr[200100], psum[200100];

array<lli, 4> find_midway(lli *arr, int cnt, lli *psum) {
    //printf("call: %d %lld\n", cnt, *psum);
    lli v = psum[0] + (psum[cnt] - psum[0]) / 2;
    int idx_where = (int)(upper_bound(psum, psum+cnt+1, v) - psum);
    lli a, b, c, d;
    if (idx_where) {
        tie(a, b, c, d) = array<lli, 4>({
            psum[idx_where] - psum[0], psum[cnt] - psum[idx_where],
            psum[idx_where - 1] - psum[0], psum[cnt] - psum[idx_where - 1]
        });
        if (a > b) swap(a, b);
        if (c > d) swap(c, d);
        //printf("%lld %lld %lld %lld\n", a, c, b, d);
        return array<lli, 4>({a, c, b, d});
    }
    tie(a, b) = plli(psum[idx_where] - psum[0], psum[cnt] - psum[idx_where]);
    if (a > b) swap(a, b);
    //printf("= %lld %lld %lld %lld\n", a, a, b, b);
    return array<lli, 4>({a, a, b, b});
}

int main() {
    int n;
    scanf("%d", &n);
    int i;
    for (i=1; i<=n; ++i) {
        scanf("%lld", arr+i);
        psum[i] = psum[i-1] + arr[i];
    }
    lli diff = 1e18;
    lli a, b, c, d, e, f, g, h;
    for (i=2; i<=n-2; ++i) {
        tie(a, b, c, d) = find_midway(arr, i, psum);
        tie(e, f, g, h) = find_midway(arr+i, n-i, psum+i);
        diff = min({
            diff,
            max(c, g) - min(a, e),
            max(d, g) - min(b, e),
            max(c, h) - min(a, f),
            max(d, h) - min(b, f)
        });
    }
    printf("%lld\n", diff);
    return 0;
}


Compiler output:
a.cc: In function 'std::array<long long int, 4> find_midway(lli*, int, lli*)':
a.cc:45:10: error: no match for 'operator=' (operand types are 'std::tuple<long long int&, long long int&, long long int&, long long int&>' and 'std::array<long long int, 4>')
   45 |         });
      |          ^
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68,
                 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:2:
/usr/include/c++/14/tuple:1930:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<const _UElements& ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(const std::tuple<_Args1 ...>&) [with _UElements = {_UElements ...}; _Elements = {long long int&, long long int&, long long int&, long long int&}]'
 1930 |         operator=(const tuple<_UElements...>& __in)
      |         ^~~~~~~~
/usr/include/c++/14/tuple:1930:9: note:   template argument deduction/substitution failed:
a.cc:45:10: note:   'std::array<long long int, 4>' is not derived from 'const std::tuple<_UTypes ...>'
   45 |         });
      |          ^
/usr/include/c++/14/tuple:1940:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<_UElements ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(std::tuple<_Args1 ...>&&) [with _UElements = {_UElements ...}; _Elements = {long long int&, long long int&, long long int&, long long int&}]'
 1940 |         operator=(tuple<_UElements...>&& __in)
      |         ^~~~~~~~
/usr/include/c++/14/tuple:1940:9: note:   template argument deduction/substitution failed:
a.cc:45:10: note:   'std::array<long long int, 4>' is not derived from 'std::tuple<_UTypes ...>'
   45 |         });
      |          ^
/usr/include/c++/14/tuple:1907:7: note: candidate: 'std::tuple< <template-parameter-1-1> >& std::tuple< <template-parameter-1-1> >::operator=(std::__conditional_t<((bool)__assignable<const _Elements& ...>()), const std::tuple< <template-parameter-1-1> >&, const std::__nonesuch&>) [with _Elements = {long long int&, long long int&, long long int&, long long int&}; std::__conditional_t<((bool)__assignable<const _Elements& ...>()), const std::tuple< <template-parameter-1-1> >&, const std::__nonesuch&> = const std::tuple<long long int&, long long int&, long long int&, long long int&>&]'
 1907 |       operator=(__conditional_t<__assignable<const _Elements&...>(),
      |       ^~~~~~~~
/usr/include/c++/14/tuple:1909:52: note:   no known conversion for argument 1 from 'std::array<long long int, 4>' to 'std::__conditional_t<true, const std::tuple<long long int&, long long int&, long long int&, long long int&>&, const std::__nonesuch&>' {aka 'const std::tuple<long long int&, long long int&, long long int&, long long int&>&'}
 1907 |       operator=(__conditional_t<__assignable<const _Elements&...>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1908 |                                 const tuple&,
      |                                 ~~~~~~~~~~~~~       
 1909 |                                 const __nonesuch&> __in)
      |                                 ~~~~~~~~~~~~~~~~~~~^~~~
/usr/include/c++/14/tuple:1918:7: note: candidate: 'std::tuple< <template-parameter-1-1> >& std::tuple< <template-parameter-1-1> >::operator=(std::__conditional_t<((bool)__assignable<_Elements ...>()), std::tuple< <template-parameter-1-1> >&&, std::__nonesuch&&>) [with _Elements = {long long int&, long long int&, long long int&, long long int&}; std::__conditional_t<((bool)__assignable<_Elements ...>()), std::tuple< <template-parameter-1-1> >&&, std::__nonesuch&&> = std::tuple<long long int&, long long int&, long long int&, long long int&>&&]'
 1918 |       operator=(__conditional_t<__assignable<_Elements...>(),
      |       ^~~~~~~~
/usr/include/c++/14/tuple:1920:47: note:   no known conversion for argument 1 from 'std::array<long long int, 4>' to 'std::__conditional_t<true, std::tuple<long long int&, long long int&, long long int&, long long int&>&&, std::__nonesuch&&>' {aka 'std::tuple<long long int&, long long int&, long long int&, long long int&>&&'}
 1918 |       operator=(__conditional_t<__assignable<_Elements...>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1919 |                                 tuple&&,
      |                                 ~~~~~~~~       
 1920 |                                 __nonesuch&&> __in)
      |                                 ~~~~~~~~~~~~~~^~~~
a.cc: In function 'int main()':
a.cc:68:51: error: no match for 'operator=' (operand types are 'std::tuple<long long int&, long long int&, long long int&, long long int&>' and 'std::array<long long int, 4>')
   68 |         tie(a, b, c, d) = find_midway(arr, i, psum);
      |                                                   ^
/usr/include/c++/14/tuple:1930:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<const _UElements& ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(const std::tuple<_Args1 ...>&) [with _UElements = {_UElements ...}; _Elements = {long long int&, long long int&, long long int&, long long int&}]'
 1930 |         operator=(const tuple<_UElements...>& __in)
      |         ^~~~~~~~
/usr/include/c++/14/tuple:1930:9: note:   template argument deduction/substitution failed:
a.cc:68:51: note:   'std::array<long long int, 4>' is not derived from 'const std::tuple<_UTypes ...>'
   68 |         tie(a, b, c, d) = find_midway(arr, i, psum);
      |                                                   ^
/usr/include/c++/14/tuple:1940:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<_UElements ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(std::tuple<_Args1 ...>&&) [with _UElements = {_UElements ...}; _Elements = {long long int&, long long int&, long long int&, long long int&}]'
 1940 |         operator=(tuple<_UElements...>&& __in)
      |         ^~~~~~~~
/usr/include/c++/14/tuple:1940:9: note:   template argument deduction/substitution failed:
a.cc:68:51: note:   'std::array<long long int, 4>' is not derived from 'std::tuple<_UTypes ...>'
   68 |         tie(a, b, c, d) = find_midway(arr, i, psum);
      |                                                   ^
/usr/include/c++/14/tuple:1907:7: note: candidate: 'std::tuple< <template-parameter-1-1> >& std::tuple< <template-parameter-1-1> >::operator=(std::__conditional_t<((bool)__assignable<const _Elements& ...>()), const std::tuple< <template-parameter-1-1> >&, const std::__nonesuch&>) [with _Elements = {long long int&, long long int&, long long int&, long long int&}; std::__conditional_t<((bool)__assignable<const _Elements& ...>()), const std::tuple< <template-parameter-1-1> >&, const std::__nonesuch&> = const std::tuple<long long int&, long long int&, long long int&, long long int&>&]'
 1907 |       operator=(__conditional_t<__assignable<const _Elements&...>(),
      |       ^~~~~~~~
/usr/include/c++/14/tuple:1909:52: note:   no known conversion for argument 1 from 'std::array<long long int, 4>' to 'std::__conditional_t<true, const std::tuple<long long int&, long long int&, long long int&, long long int&>&, const std::__nonesuch&>' {aka 'const std::tuple<long long int&, long long int&, long long int&, long long int&>&'}
 1907 |       operator=(__conditional_t<__assignable<const _Elements&...>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1908 |                                 const tuple&,
      |                                 ~~~~~~~~~~~~~       
 1909 |                                 const __nonesuch&> __in)
      |                                 ~~~~~~~~~~~~~~~~~~~^~~~
/usr/include/c++/14/tuple:1918:7: note: candidate: 'std::tuple< <template-parameter-1-1> >& std::tuple< <template-parameter-1-1> >::operator=(std::__conditional_t<((bool)__assignable<_Elements ...>()), std::tuple< <template-parameter-1-1> >&&, std::__nonesuch&&>) [with _Elements = {long long int&, long long int&, long long int&, long long int&}; std::__conditional_t<((bool)__assignable<_Elements ...>()), std::tuple< <template-parameter-1-1> >&&, std::__nonesuch&&> = std::tuple<long long int&, long long int&, long long int&, long long int&>&&]'
 1918 |       operator=(__conditional_t<__assignable<_Elements...>(),
      |       ^~~~~~~~
/usr/include/c++/14/tuple:1920:47: note:   no known conversion for argument 1 from 'std::array<long long int, 4>' to 'std::__conditional_t<true, std::tuple<long long int&, long long int&, long long int&, long long int&>&&, std::__nonesuch&&>' {aka 'std::tuple<long long int&, long long int&, long long int&, long long int&>&&'}
 1918 |       operator=(__conditional_t<__assignable<_Elements...>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1919 |                                 tuple&&,
      |                                 ~~~~~~~~       
 1920 |                                 __nonesuch&&> __in)
      |                                 ~~~~~~~~~~~~~~^~~~
a.cc:69:57: error: no match for 'operator=' (operand types are 'std::tuple<long long int&, long long int&, long long int&, long long int&>' and 'std::array<long long int, 4>')
   69 |         tie(e, f, g, h) = find_midway(arr+i, n-i, psum+i);
      |                                                         ^
/usr/include/c++/14/tuple:1930:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<const _UElements& ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(const std::tuple<_Args1 ...>&) [with _UElements = {_UElements ...}; _Elements = {long long int&, long long int&, long long int&, long long int&}]'
 1930 |