## Editorial for DMOPC '18 Contest 2 P4 - Damage Output

Remember to use this editorial

**only**when stuck, and**not to copy-paste code from it**. Please be respectful to the problem author and editorialist.**Submitting an official solution before solving the problem yourself is a bannable offence.**Authors:

For the first subtask, brute-force all subarrays and their sums.

**Time Complexity:**

For the second subtask, check all subarrays and use a prefix sum to calculate their sums.

**Time Complexity:**

For the third subtask, we do a two-pointer walk. Keep a left and right pointer, initially both set to the starting index. If the subarray currently described by the two pointers has a sum less than , move the right pointer. Otherwise, move the left pointer. Since all the elements are non-negative, this will find the smallest subarray with sum at least .

**Time Complexity:**

## Comments

Typo on first line(brute-forc)

Fixed. Thank you for pointing that out!