CodeForces Div 2 problem Books (279/B)

Problem Statement: https://codeforces.com/problemset/problem/279/B

My Code: https://ide.codingblocks.com/s/90408

Most Probably I am doing something wrong inside maxSum function which returns the maximum sum till he can read the books in time t from the array of cumulative sum (aka prefix sum) but I am not able to understand what is going wrong?

You haven’t created a sliding window

suppose array is
1 3 4 2 1 4 6 7
then prefix array is
1 4 8 10 11 15 21 28

all subarrays of size 3 are:
8-0 = 8, 10-1 = 9, 11-4 = 7, 15-8=7, 21-10=11, 28-11 = 17
8, 9, 7, 7, 11, 17
u have to return minimum of this = 7

but u r doing
in the third loop:
maximum = max(1,4)
maximum = max(4,8)
maximum = max(8,10)

return maximum

thanks I will create a sliding window.

u can also do like for cumilative array for each element make a binary search for its left and right part and if u are able to read then move be =mid+1 compl. 2nlogn