Easy Peasy Cpp Solution O(B) time , O(1) space


#1
int Solution::solve(vector<int> &A, int B) {
    int n = A.size();
    int suff = 0;
    for(int i = n-1;i>=n-B;i--) suff+=A[i];
    int ans = suff,pref = 0;
    for(int i = 0;i<B;i++){
        pref+=A[i];
        suff-=A[n-B+i];
        ans = max(ans,pref+suff);
    }
    return ans;
}

#2