Subarray Sums


Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 128M

Problem type

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 (1N2105) and K (1014K1014).

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%]

1N300

Subtask 2 [30%]

1N2000

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

There are no comments at the moment.