Language: C++

#include <vector>
#include <algorithm>
#include <iostream>
#include <functional>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(i>0){
            a[i] = a[i] + a[i-1];
        }
    }

    int center = 1;
    int left = 0;
    int right = 2;
    vector<long long> PQRS(4);
    long long ans = 0x3fffffffffffffff ;
    int next_left = 0;
    int next_right = 2;
    int calc_cnt=0;
    while(center<n-2){
        long long L_min = 0x3fffffffffffffff;
        long long R_min = 0x3fffffffffffffff;

for(left=next_left;left<center&&a[center]-a[left]*2>a[center]-a[left+1]*2;left++){
            long long b = a[left];
            long long c = a[center]-a[left];
            if( abs(b-c)<L_min)
            {
                PQRS[0] = b;
                PQRS[1] = c;
                L_min = abs(b-c);
            }
            next_left=left;
            calc_cnt++;
        }

        next_right = max(next_right,center+1);

for(right=next_right;right<n-1;&&a[n-1]-a[right]*2<a[n-1]-a[right+1]*2;right++){
            long long d = a[right]-a[center];
            long long e = a[n-1]-a[right];
            if( abs(e-d)<R_min)
            {
                PQRS[2] = d;
                PQRS[3] = e;
                R_min = abs(e-d);
            }
            next_right=right;
            calc_cnt++;
        }

        long long max_elem = *max_element(PQRS.begin(),PQRS.end());
        long long min_elem = *min_element(PQRS.begin(),PQRS.end());
        if( max_elem-min_elem < ans){
            ans = max_elem-min_elem;
        //    cout << "update ans::" << ans;
        }
        center ++;
    }
    cout << ans << endl;
    //cout << calc_cnt << endl;

    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:45:35: error: expected ')' before '[' token
   45 | for(right=next_right;right<n-1;&&a[n-1]-a[right]*2<a[n-1]-a[right+1]*2;right++){
      |    ~                              ^
      |                                   )
a.cc:45:37: error: expected ',' before '-' token
   45 | for(right=next_right;right<n-1;&&a[n-1]-a[right]*2<a[n-1]-a[right+1]*2;right++){
      |                                     ^
      |                                     ,
a.cc:45:37: error: expected identifier before '-' token
a.cc: In lambda function:
a.cc:45:40: error: expected '{' before '-' token
   45 | for(right=next_right;right<n-1;&&a[n-1]-a[right]*2<a[n-1]-a[right+1]*2;right++){
      |                                        ^
a.cc: In function 'int main()':
a.cc:45:40: error: no match for 'operator-' (operand types are 'main()::<lambda()>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   45 | for(right=next_right;right<n-1;&&a[n-1]-a[right]*2<a[n-1]-a[right+1]*2;right++){
      |                                   ~~~~~^
      |                                   |
      |                                   main()::<lambda()>
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/vector:62,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:45:50: note:   'main()::<lambda()>' is not derived from 'const std::reverse_iterator<_Iterator>'
   45 | for(right=next_right;right<n-1;&&a[n-1]-a[right]*2<a[n-1]-a[right+1]*2;right++){
      |                                                  ^
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:45:50: note:   'main()::<lambda()>' is not derived from 'const std::move_iterator<_IteratorL>'
   45 | for(right=next_right;right<n-1;&&a[n-1]-a[right]*2<a[n-1]-a[right+1]*2;right++){
      |                                                  ^
a.cc:45:79: error: expected ';' before ')' token
   45 | for(right=next_right;right<n-1;&&a[n-1]-a[right]*2<a[n-1]-a[right+1]*2;right++){
      |                                                                               ^
      |                                                                               ;
a.cc:45:34: error: label 'a' used but not defined
   45 | for(right=next_right;right<n-1;&&a[n-1]-a[right]*2<a[n-1]-a[right+1]*2;right++){
      |                                  ^