Subarray Sums
You are given an array with \(N\) integers ranging from \(-10^9\) to \(10^9\). Check whether or not all subarray sums are less than or equal to \(K\).
A subarray is a non-empty contiguous segment of an array. For example, \([1, 3, -2]\) is a subarray of \([0, 1, 1, 3, -2, 4 5]\).
Input Specification
The first line of the input will contain two integers \(N\) \((1 \le N \le 2 \cdot 10^5)\) and \(K\) \((-10^{14} \le K \le 10^{14})\).
The second line of the input will contain \(N\) integers ranging from \(-10^9\) to \(10^9\) inclusive, each separated by a space.
Note that C++ and Java users will need to use long long
or long
datatypes to store \(K\).
Output Specification
Output YES
if all subarray sums are less than or equal to \(K\), and NO
otherwise.
Subtasks
Subtask 1 [30%]
\(1 \le N \le 300\)
Subtask 2 [30%]
\(1 \le N \le 2000\)
Subtask 3 [40%]
No additional constraints.
Sample Input
7 8
5 -1 -1 2 3 1 -2
Sample Output
NO
Sample Explanation
The sum of the subarray \([5, -1, -1, 2, 3, 1]\) exceeds the value \(8\).
Comments