Subarray Sums
You are given an array with N integers ranging from −109 to 109. 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,45].
Input Specification
The first line of the input will contain two integers N (1≤N≤2⋅105) and K (−1014≤K≤1014).
The second line of the input will contain N integers ranging from −109 to 109 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≤N≤300
Subtask 2 [30%]
1≤N≤2000
Subtask 3 [40%]
No additional constraints.
Sample Input
Copy
7 8
5 -1 -1 2 3 1 -2
Sample Output
Copy
NO
Sample Explanation
The sum of the subarray [5,−1,−1,2,3,1] exceeds the value 8.
Comments