I apologize for the code formatting. I am not able to structure it.

```
public int solve(ArrayList<Integer> A, int B) {
Deque<Integer> dq1 = new ArrayDeque<Integer>(B);
int sum = 0;
for(int i=0; i<B; i++)
{
sum += A.get(i);
dq1.addLast(A.get(i));
}
int max = Integer.MIN_VALUE;
int n = A.size()-1;
for(int i=0;i<B;i++)
{
max = Math.max(max, sum);
sum = sum - dq1.removeLast();
sum = sum + A.get(n-i);
dq1.addFirst(A.get(n-i));
}
return max;
}
}```
```