Language: C++

#include "iostream"
#include "vector"
#include "array"
#include "string"
#include "algorithm"
#include "functional"

using namespace std;
#define rep(p,q) for(int i = p;i < q;i++)

// ab >= a + b -> a,b枚数分
// ab < a + b ab < 2 * min(a,b)
// ab < a + b ab >= 2 * min(a,b)

int main(void) {
	long long int n,c;
	cin >> n >> c;
	vector<pair<long long int,long long int>> sushi = vector<pair<long long int,long long int>>();
	vector<long long int> croc = vector<long long int>();
	vector<long long int> antiC = vector<long long int>();
	pair<long long int, long long int> cMax = pair<long long int,long long int>(0, 0);
	pair<long long int, long long int> antiMax = pair<long long int, long long int>(0, 0);
	rep(0, n) {
		long long int x, v;
		cin >> x >> v;
		if (croc.size() >= 1) {
			auto su = sushi[i - 1];
			long long int clr = v - (x - su.first) + su.second;
			if (cMax.first < clr) {
				cMax = pair<long long int, long long int>(clr,i);
			}
			croc.push_back(clr);
		}
		else {
			long long int clr = v - x;
			if (cMax.first < clr) {
				cMax = pair<long long int, long long int>(clr, i);
			}
			croc.push_back(clr);
		}
		sushi.push_back(pair<long long int, long long int>(x, v));
	}
	sushi = sort(sushi.begin, sushi.end, std::greater<int>());
	
	rep(0, n) {
		pair<long long int, long long int> su = sushi[i];
		long long int clr = su.second - su.first;
		if (antiC.size() < 1) {
			antiC.push_back(clr);
		}
		else {
			clr += sushi[i - 1].first + sushi[i - 1].second;
			antiC.push_back(clr);
			if (antiMax.first < clr) {
				antiMax = pair<long long int, long long int>(clr, i);
			}
		}
	}

	int ans = 0;
	if (cMax.first > antiMax.first) {
		int max = *std::max_element(antiC.begin(), antiC.begin() + n - cMax.second);
		ans += cMax.first;
		if (max > 0) {
			ans += max;
		}
		cout << ans << endl;
	}
	else if (cMax.first <= antiMax.first) {
		int max = *std::max_element(croc.begin(), croc.begin() + n - antiMax.second);
		ans += antiMax.first;
		if (max > 0) {
			ans += max;
		}
		cout << ans << endl;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:21: error: no matching function for call to 'sort(<unresolved overloaded function type>, <unresolved overloaded function type>, std::greater<int>)'
   43 |         sushi = sort(sushi.begin, sushi.end, std::greater<int>());
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_algo.h:4762:5: note: candidate: 'template<class _RAIter> void std::sort(_RAIter, _RAIter)'
 4762 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4762:5: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/14/bits/stl_algo.h:4793:5: note: candidate: 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
 4793 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note:   template argument deduction/substitution failed:
a.cc:43:21: note:   couldn't deduce template parameter '_RAIter'
   43 |         sushi = sort(sushi.begin, sushi.end, std::greater<int>());
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note:   candidate expects 4 arguments, 3 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note:   template argument deduction/substitution failed:
a.cc:43:21: note:   couldn't deduce template parameter '_ExecutionPolicy'
   43 |         sushi = sort(sushi.begin, sushi.end, std::greater<int>());
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~