Language: C++

import java.io.IOException;
import java.util.Collections;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

class Solution {
	public int findMaxSequence(LinkedList<Integer> deque, int k) {
		int n = deque.size();
		int min = Math.min(n, k);
		LinkedList<Integer> list = new LinkedList<>();
		int max = Integer.MIN_VALUE;
		for (int i = 0; i <= min; ++i) {
			for (int j = min - i; j >= 0; j--) {
				if (j == 0 && i == j) {
					break;
				}
				Deque<Integer> newDeque = (Deque<Integer>) deque.clone();
				list.clear();
				int a = i;
				int b = j;
				while (a > 0) {
					list.add(newDeque.pollFirst());
					a--;
				}
				while (b > 0) {
					list.add(newDeque.pollLast());
					b--;
				}
				Collections.sort(list);
				int remind = min - i - j;

				while (remind > 0 && !list.isEmpty() && list.peek() <= 0) {
					list.poll();
					remind--;
				}
				int newMax = 0;
				for (Integer integer : list)
					newMax += integer;
				if (max < newMax)
					max = newMax;
			}
		}
		return max < 0 ? 0 : max;
	}
}

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		LinkedList<Integer> deque = new LinkedList<>();
		for (int i = 0; i < n; ++i) {
			deque.addLast(scanner.nextInt());
		}
		int ret = new Solution().findMaxSequence(deque, k);

		String out = String.valueOf(ret);

		System.out.print(out);
	}
}

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.util.Collections;
      | ^~~~~~
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.util.Deque;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.util.LinkedList;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.util.Scanner;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:15: error: expected ':' before 'int'
    8 |         public int findMaxSequence(LinkedList<Integer> deque, int k) {
      |               ^~~~
      |               :
a.cc:8:36: error: 'LinkedList' has not been declared
    8 |         public int findMaxSequence(LinkedList<Integer> deque, int k) {
      |                                    ^~~~~~~~~~
a.cc:8:46: error: expected ',' or '...' before '<' token
    8 |         public int findMaxSequence(LinkedList<Integer> deque, int k) {
      |                                              ^
a.cc:46:2: error: expected ';' after class definition
   46 | }
      |  ^
      |  ;
a.cc: In member function 'int Solution::findMaxSequence(int)':
a.cc:9:25: error: 'deque' was not declared in this scope
    9 |                 int n = deque.size();
      |                         ^~~~~
a.cc:10:27: error: 'Math' was not declared in this scope
   10 |                 int min = Math.min(n, k);
      |                           ^~~~
a.cc:10:39: error: 'k' was not declared in this scope
   10 |                 int min = Math.min(n, k);
      |                                       ^
a.cc:11:17: error: 'LinkedList' was not declared in this scope
   11 |                 LinkedList<Integer> list = new LinkedList<>();
      |                 ^~~~~~~~~~
a.cc:11:28: error: 'Integer' was not declared in this scope
   11 |                 LinkedList<Integer> list = new LinkedList<>();
      |                            ^~~~~~~
a.cc:11:37: error: 'list' was not declared in this scope
   11 |                 LinkedList<Integer> list = new LinkedList<>();
      |                                     ^~~~
a.cc:11:48: error: 'LinkedList' does not name a type
   11 |                 LinkedList<Integer> list = new LinkedList<>();
      |                                                ^~~~~~~~~~
a.cc:11:59: error: expected primary-expression before '>' token
   11 |                 LinkedList<Integer> list = new LinkedList<>();
      |                                                           ^
a.cc:11:61: error: expected primary-expression before ')' token
   11 |                 LinkedList<Integer> list = new LinkedList<>();
      |                                                             ^
a.cc:18:33: error: 'Deque' was not declared in this scope
   18 |                                 Deque<Integer> newDeque = (Deque<Integer>) deque.clone();
      |                                 ^~~~~
a.cc:18:48: error: 'newDeque' was not declared in this scope
   18 |                                 Deque<Integer> newDeque = (Deque<Integer>) deque.clone();
      |                                                ^~~~~~~~
a.cc:18:74: error: expected primary-expression before ')' token
   18 |                                 Deque<Integer> newDeque = (Deque<Integer>) deque.clone();
      |                                                                          ^
a.cc:30:33: error: 'Collections' was not declared in this scope
   30 |                                 Collections.sort(list);
      |                                 ^~~~~~~~~~~
a.cc:38:46: error: expected ';' before 'integer'
   38 |                                 for (Integer integer : list)
      |                                              ^~~~~~~
a.cc:40:33: error: expected primary-expression before 'if'
   40 |                                 if (max < newMax)
      |                                 ^~
a.cc:40:33: error: expected ';' before 'if'
a.cc:40:33: error: expected primary-expression before 'if'
a.cc:40:33: error: expected ')' before 'if'
a.cc:38:37: note: to match this '('
   38 |                                 for (Integer integer : list)
      |                                     ^
a.cc: At global scope:
a.cc:48:1: error: expected unqualified-id before 'public'
   48 | public class Main {
      | ^~~~~~