Language: C++

#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;

int main()
{
	int size;
	cin >> size;
	vector <int> arr(size), pre(size);

	for (int i = 0; i < size; i++)
		cin >> arr[i];

	pre[0] = arr[0];

	for (int i = 1; i < size; i++)
		pre[i] = pre[i - 1] + arr[i];

	int i1 = 0, i3 = 2, currDiff = abs(2 * pre[i3] - pre[1] - pre[size - 1]);

	while (true)
	{
		i3++;

		int newDiff = abs(2 * pre[i3] - pre[1] - pre[size - 1]);

		if (newDiff > currDiff)
		{
			i3--;

			break;
		}
	}

	int minDiff1,
		minDiff2;

	int ans = max({ pre[i1], pre[1] - pre[i1], pre[i3] - pre[1], pre[size - 1] - pre[i3] }) - min({ pre[i1], pre[1] - pre[i1], pre[i3] - pre[1], pre[size - 1] - pre[i3] });

	for (int i2 = 2; i2 < size - 2; i2++)
	{
		minDiff1 = abs(2 * pre[i1] - pre[i2]);
		minDiff2 = abs(2 * pre[i3] - pre[i2] - pre[size - 1]);

		while (i1 < i2)
		{
			int nextDiff1 = abs(2 * pre[i1 + 1] - pre[i2]);

			if (nextDiff1 <= minDiff1)
			{
				minDiff1 = nextDiff1;

				i1++;
			}

			else
				break;
		}

		while (i3 < size - 1)
		{
			int nextDiff2 = abs(2 * pre[i3 + 1] - pre[i2] - pre[size - 1]);//(pre[i3 + 1] - pre[i2] - pre[size - 1] + pre[i3 + 2]);

			if (nextDiff2 <= minDiff2)
			{
				minDiff2 = nextDiff2;

				i3++;
			}

			else
				break;
		}

		ans = min(ans, max({ pre[i1], pre[i2] - pre[i1], pre[i3] - pre[i2], pre[size - 1] - pre[i3] }) - min({ pre[i1], pre[i2] - pre[i1], pre[i3] - pre[i2], pre[size - 1] - pre[i3] }));
	}

	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:22: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   42 |         int ans = max({ pre[i1], pre[1] - pre[i1], pre[i3] - pre[1], pre[size - 1] - pre[i3] }) - min({ pre[i1], pre[1] - pre[i1], pre[i3] - pre[1], pre[size - 1] - pre[i3] });
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:42:102: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   42 |         int ans = max({ pre[i1], pre[1] - pre[i1], pre[i3] - pre[1], pre[size - 1] - pre[i3] }) - min({ pre[i1], pre[1] - pre[i1], pre[i3] - pre[1], pre[size - 1] - pre[i3] });
      |                                                                                                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:79:35: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   79 |                 ans = min(ans, max({ pre[i1], pre[i2] - pre[i1], pre[i3] - pre[i2], pre[size - 1] - pre[i3] }) - min({ pre[i1], pre[i2] - pre[i1], pre[i3] - pre[i2], pre[size - 1] - pre[i3] }));
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:79:117: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   79 |                 ans = min(ans, max({ pre[i1], pre[i2] - pre[i1], pre[i3] - pre[i2], pre[size - 1] - pre[i3] }) - min({ pre[i1], pre[i2] - pre[i1], pre[i3] - pre[i2], pre[size - 1] - pre[i3] }));
      |                                                                                                                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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