Language: C++

#include <cstdio>
#include <iostream>
#include <algorithm>

#define Mkp make_pair

using namespace std;

typedef long long LL;

const int N = 200005;

int n;
int a[N];
LL s[N], ans = (LL)1e18;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
  for (int i = 2; i < n - 1; ++i) {
    int l1 = 0, r1 = i;
    for (int md; l1 < r1; ) {
      md = (l1 + r1) >> 1;
      if (s[md] < s[i] - s[md]) {
        l1 = md + 1;
      } else {
        r1 = md;
      }
    }
    int l2 = i, r2 = n;
    for (int md; l2 < r2; ) {
      md = (l2 + r2) >> 1;
      if (s[md] - s[i] < s[n] - s[md]) {
        l2 = md + 1;
      } else {
        r2 = md;
      }
    }
    vector<pair<LL, LL> > a;
    vector<pair<LL, LL> > b;
    if (l1 < i) a.push_back(Mkp(s[l1], s[i] - s[l1]));
    if (l1 > 1) --l1, a.push_back(Mkp(s[l1], s[i] - s[l1]));
    if (l2 < n) b.push_back(Mkp(s[l2] - s[i], s[n] - s[l2]));
    if (l2 > i + 1) --l2, b.push_back(Mkp(s[l2] - s[i], s[n] - s[l2]));
    for (auto p : a) {
      for (auto q : b) {
        LL a1 = max(max(p.first, p.second), max(q.first, q.second));
        LL a2 = min(min(p.first, p.second), min(q.first, q.second));
        ans = min(ans, a1 - a2);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:5: error: 'vector' was not declared in this scope
   40 |     vector<pair<LL, LL> > a;
      |     ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <algorithm>
  +++ |+#include <vector>
    4 | 
a.cc:40:25: error: expected primary-expression before '>' token
   40 |     vector<pair<LL, LL> > a;
      |                         ^
a.cc:41:25: error: expected primary-expression before '>' token
   41 |     vector<pair<LL, LL> > b;
      |                         ^
a.cc:41:27: error: 'b' was not declared in this scope
   41 |     vector<pair<LL, LL> > b;
      |                           ^
a.cc:42:19: error: request for member 'push_back' in 'a', which is of non-class type 'int [200005]'
   42 |     if (l1 < i) a.push_back(Mkp(s[l1], s[i] - s[l1]));
      |                   ^~~~~~~~~
a.cc:43:25: error: request for member 'push_back' in 'a', which is of non-class type 'int [200005]'
   43 |     if (l1 > 1) --l1, a.push_back(Mkp(s[l1], s[i] - s[l1]));
      |                         ^~~~~~~~~
a.cc:48:27: error: request for member 'first' in 'p', which is of non-class type 'int'
   48 |         LL a1 = max(max(p.first, p.second), max(q.first, q.second));
      |                           ^~~~~
a.cc:48:36: error: request for member 'second' in 'p', which is of non-class type 'int'
   48 |         LL a1 = max(max(p.first, p.second), max(q.first, q.second));
      |                                    ^~~~~~
a.cc:49:27: error: request for member 'first' in 'p', which is of non-class type 'int'
   49 |         LL a2 = min(min(p.first, p.second), min(q.first, q.second));
      |                           ^~~~~
a.cc:49:36: error: request for member 'second' in 'p', which is of non-class type 'int'
   49 |         LL a2 = min(min(p.first, p.second), min(q.first, q.second));
      |                                    ^~~~~~