Language: C++

#include <algorithm>
//#include <cstdio>
//#include <functional>
//#include <bits/stdc++.h>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define rt0 return 0
using namespace std;
 
int main()
{
	int n,i,j;
	long long c,ans=0,temp,ans1;

	cin>>n>>c;
	
	vector<int> v(n);
	vector<long long> x(n);

	for(i=0;i<n;i++) cin>>x[i]>>v[i];
	
	ans=0;
	
	temp=0;
	for(i=0;i<n;i++) {//顺时针走一圈 
		temp-=x[i];
		if(i>0) temp+=x[i-1];
		temp+=v[i];
		ans=max(ans,temp);
	}
	
	temp=0;
	for(i=n-1;i>=0;i--) {//逆时针走一圈 
		temp-=(c-x[i]);
		if(i<(n-1)) temp+=(c-x[i+1]);
		temp+=v[i];
		ans=max(ans,temp);
	}	


	for(j=0;j<n-1;j++) {//顺时针走到j，
		temp=0;
	 	for(i=0;i<=j;i++) {
			temp-=x[i];
			if(i>0) temp+=x[i-1];
			temp+=v[i];
		}
		temp-=x[j];
		for(i=n-1;i>=j+1;i--) {//逆时针走到j+1
			temp-=(c-x[i]);
			if(i<(n-1)) temp+=(c-x[i+1]);
			temp+=v[i];

		}		
	}

	for(j=1;j<n-1;j++) {//逆时针走到j，
		temp=0;
		for(i=n-1;i>=j;i--) {
			temp-=(c-x[i]);
			if(i<(n-1)) temp+=(c-x[i+1]);
			temp+=v[i];
		}	
		temp-=x[j];
		for(i=0;i<=j-1;i++) {//顺时针走到j-1
			temp-=x[i];
			if(i>0) temp+=x[i-1];
			temp+=v[i];
			ans=max(ans,temp);
		}
	}
				
	cout<<ans;
    rt0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:9: error: 'vector' was not declared in this scope
   32 |         vector<int> v(n);
      |         ^~~~~~
a.cc:6:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    5 | #include <iostream>
  +++ |+#include <vector>
    6 | //#include <cfloat>
a.cc:32:16: error: expected primary-expression before 'int'
   32 |         vector<int> v(n);
      |                ^~~
a.cc:33:16: error: expected primary-expression before 'long'
   33 |         vector<long long> x(n);
      |                ^~~~
a.cc:35:31: error: 'x' was not declared in this scope
   35 |         for(i=0;i<n;i++) cin>>x[i]>>v[i];
      |                               ^
a.cc:35:37: error: 'v' was not declared in this scope
   35 |         for(i=0;i<n;i++) cin>>x[i]>>v[i];
      |                                     ^
a.cc:41:23: error: 'x' was not declared in this scope
   41 |                 temp-=x[i];
      |                       ^
a.cc:43:23: error: 'v' was not declared in this scope
   43 |                 temp+=v[i];
      |                       ^
a.cc:49:26: error: 'x' was not declared in this scope
   49 |                 temp-=(c-x[i]);
      |                          ^
a.cc:51:23: error: 'v' was not declared in this scope
   51 |                 temp+=v[i];
      |                       ^
a.cc:59:31: error: 'x' was not declared in this scope
   59 |                         temp-=x[i];
      |                               ^
a.cc:61:31: error: 'v' was not declared in this scope
   61 |                         temp+=v[i];
      |                               ^
a.cc:63:23: error: 'x' was not declared in this scope
   63 |                 temp-=x[j];
      |                       ^
a.cc:67:31: error: 'v' was not declared in this scope
   67 |                         temp+=v[i];
      |                               ^
a.cc:75:34: error: 'x' was not declared in this scope
   75 |                         temp-=(c-x[i]);
      |                                  ^
a.cc:77:31: error: 'v' was not declared in this scope
   77 |                         temp+=v[i];
      |                               ^
a.cc:79:23: error: 'x' was not declared in this scope
   79 |                 temp-=x[j];
      |                       ^
a.cc:83:31: error: 'v' was not declared in this scope
   83 |                         temp+=v[i];
      |                               ^