Language: C++

 /*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#pragma GCC optimize "-oFast"
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
    
     
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } 
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define rank rank228
#define y1 y1228                                                         
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
const string FILENAME = "input";
const int MAXN = 200228;


typedef long long ll;
ll n,c,s,ans,x[N],cal[N],mx[N]={0},mx2[N]={0};
int main(){
  ll i;
  cin>>n>>c;
  for(i=0;i<N;i++){
    scanf("%lld %lld",&x[i],&cal[i]);
  }  
  //clockwise
  for(i=n-1;i>=0;i--){
    s+=cal[i];//consumed calories
    mx[i] = max(mx[i+1],s-(c-x[i]));//c-x[i]: used calories
    mx2[i] = max(mx2[i+1],s-(c-x[i])*2);//return first point
  }
  
  ans = max(mx[0],mx2[0]);
  s=0;//initialize calories
  
  //anticlockwise
  for(i=0;i<n;i++){
    s+=cal[i];
    ans = max(ans, s-x[i]*2 + mx[i+1]);//return first point 
    ans = max(ans, s-x[i] + mx2[i+1]);
  }
  cout << ans;
  return 0;
}


Compiler output:
a.cc:17:22: warning: bad option '-oFast' to pragma 'optimize' [-Wpragmas]
   17 | #pragma GCC optimize "-oFast"
      |                      ^~~~~~~~
a.cc:42:65: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   42 | template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
      |                                                                 ^
a.cc:43:65: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   43 | template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
      |                                                                 ^
a.cc:44:97: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   44 | template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
      |                                                                                                 ^
a.cc:45:90: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   45 | template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
      |                                                                                          ^
a.cc:46:84: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   46 | template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
      |                                                                                    ^
a.cc:47:77: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   47 | template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
      |                                                                             ^
a.cc:48:81: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   48 | template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
      |                                                                                 ^
a.cc:49:86: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   49 | template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
      |                                                                                      ^
a.cc:50:91: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   50 | template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
      |                                                                                           ^
a.cc:51:96: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   51 | template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
      |                                                                                                ^
a.cc:52:96: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   52 | template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
      |                                                                                                ^
a.cc:53:106: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   53 | template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
      |                                                                                                          ^
a.cc:70:16: error: 'N' was not declared in this scope
   70 | ll n,c,s,ans,x[N],cal[N],mx[N]={0},mx2[N]={0};
      |                ^
a.cc:70:23: error: 'N' was not declared in this scope
   70 | ll n,c,s,ans,x[N],cal[N],mx[N]={0},mx2[N]={0};
      |                       ^
a.cc:70:29: error: 'N' was not declared in this scope
   70 | ll n,c,s,ans,x[N],cal[N],mx[N]={0},mx2[N]={0};
      |                             ^
a.cc:70:40: error: 'N' was not declared in this scope
   70 | ll n,c,s,ans,x[N],cal[N],mx[N]={0},mx2[N]={0};
      |                                        ^
a.cc:71:10: warning: bad option '-oFast' to attribute 'optimize' [-Wattributes]
   71 | int main(){
      |          ^
a.cc: In function 'int main()':
a.cc:74:13: error: 'N' was not declared in this scope
   74 |   for(i=0;i<N;i++){
      |             ^
a.cc:75:24: error: 'x' was not declared in this scope
   75 |     scanf("%lld %lld",&x[i],&cal[i]);
      |                        ^
a.cc:75:30: error: 'cal' was not declared in this scope
   75 |     scanf("%lld %lld",&x[i],&cal[i]);
      |                              ^~~
a.cc:79:8: error: 'cal' was not declared in this scope
   79 |     s+=cal[i];//consumed calories
      |        ^~~
a.cc:80:5: error: 'mx' was not declared in this scope
   80 |     mx[i] = max(mx[i+1],s-(c-x[i]));//c-x[i]: used calories
      |     ^~
a.cc:80:30: error: 'x' was not declared in this scope
   80 |     mx[i] = max(mx[i+1],s-(c-x[i]));//c-x[i]: used calories
      |                              ^
a.cc:81:5: error: 'mx2' was not declared in this scope
   81 |     mx2[i] = max(mx2[i+1],s-(c-x[i])*2);//return first point
      |     ^~~
a.cc:84:13: error: 'mx' was not declared in this scope
   84 |   ans = max(mx[0],mx2[0]);
      |             ^~
a.cc:84:19: error: 'mx2' was not declared in this scope
   84 |   ans = max(mx[0],mx2[0]);
      |                   ^~~
a.cc:89:8: error: 'cal' was not declared in this scope
   89 |     s+=cal[i];
      |        ^~~
a.cc:90:22: error: 'x' was not declared in this scope
   90 |     ans = max(ans, s-x[i]*2 + mx[i+1]);//return first point
      |                      ^