Language: C++

import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        long c = Long.parseLong(input[1]);
        long forwardMax[] = new long[n+1];
        long backwardMax[] = new long[n+1];

        long positions[] = new long[n+1];
        long values[] = new long[n+1];

        positions[0] = 0;
        values[0] = 0;
        for(int i = 1; i <= n; i++){
            input = br.readLine().split(" ");
            positions[i] = Long.parseLong(input[0]);
            values[i] = Long.parseLong(input[1]);
        }

        long max = 0;
        long sum = 0;
        for(int i = 0; i <= n; i++){
            sum += values[i];
            max = Math.max(max, sum - positions[i]);
            forwardMax[i] = max;
        }

        max = 0;
        sum = 0;
        for(int i = n; i >= 0; i--){
            sum += values[i];
            max = Math.max(max, sum - (c - positions[i]) );
            backwardMax[i] = max;
        }

        long res = 0;

        for(int i = 0; i <= n; i++){
            // forward OA + OA + OB
            res = Math.max(res, forwardMax[i]);
            if(i != n)
                res = Math.max(res, forwardMax[i] - (positions[i]) + backwardMax[i+1]);
            
            // backward OA + OB + OB        
            res = Math.max(res , backwardMax[i]);
            if(i != 0) 
                res = Math.max(res , backwardMax[i] - (c - positions[i]) + forwardMax[i-1]);
        }

        System.out.println(res);
    }
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.io.IOException;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.io.BufferedReader;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.io.InputStreamReader;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:11: error: expected ':' before 'static'
    6 |     public static void main(String[] args) throws IOException{
      |           ^~~~~~~
      |           :
a.cc:6:29: error: 'String' has not been declared
    6 |     public static void main(String[] args) throws IOException{
      |                             ^~~~~~
a.cc:6:38: error: expected ',' or '...' before 'args'
    6 |     public static void main(String[] args) throws IOException{
      |                                      ^~~~
a.cc:6:42: error: expected ';' at end of member declaration
    6 |     public static void main(String[] args) throws IOException{
      |                                          ^
      |                                           ;
a.cc:6:44: error: 'throws' does not name a type
    6 |     public static void main(String[] args) throws IOException{
      |                                            ^~~~~~
a.cc:57:2: error: expected ';' after class definition
   57 | }
      |  ^
      |  ;