Editorial for DMOPC '18 Contest 5 P3 - A Familiar Problem
Submitting an official solution before solving the problem yourself is a bannable offence.
For the first subtask, we can iterate over all subarrays subarrays, and find their sum in time, keeping track of the longest one where the sum does not exceed .
For the second subtask, we can find the sum in time by using a prefix sum array.
For the third subtask, we can use a 2-pointer approach. As the right pointer advances, the left pointer should point to the left-most index where the sum is less than . Since both pointers will only move from left to right, the time complexity is .