This page is still under construction.

Parts of this page are still being built. What you see may change.

Fish

Time limit1sMemory limit64 MB

Summary
Count contiguous subarrays whose sum is at least K.
Level

Medium7 of 10

Topics
Prefix sum, Divide and conquer, Sorting, Binary search
Solved
No attempts yet

Problem

Kuching the cat likes eating fish. He accidentally bought a fish that is far too large and does not want to eat all of it. He cut the fish into NN segments from head to tail, numbered 1 to NN, and gave every segment a satisfaction rating. The higher the rating, the more Kuching enjoys that segment. Fish only tastes good when it is eaten as a chunk. A chunk is one or more segments with consecutive numbers.

Kuching is picky and does not enjoy a chunk whose satisfaction ratings sum to less than KK, so the sum has to be at least KK. Count the ways to cut a single chunk out of the fish that Kuching would enjoy eating. Segments outside the chunk are thrown away.

A chunk holds at least 1 segment and at most NN segments, which is the whole fish.

Input

The first line contains two 32-bit signed integers NN and KK. NN is always positive, while KK may be positive, zero, or negative. (1≤N≤200,0001 \le N \le 200{,}000)

The second line contains the satisfaction ratings of the NN segments in order. The ii-th integer is the rating of the ii-th segment. Every rating fits in a 32-bit signed integer and may be positive, zero, or negative.

Output

Print a single integer, the number of ways to cut out one chunk whose satisfaction ratings sum to at least KK.

Hint

In the first example Kuching cut the fish into 5 segments with ratings 1, -2, 3, -4, 5, and he only enjoys chunks whose sum is at least 2. The six chunks he enjoys are (1, -2, 3), (1, -2, 3, -4, 5), (-2, 3, -4, 5), (3), (3, -4, 5) and (5). Every other chunk sums to less than KK. Segments 1, 3 and 5 are not consecutive, so (1, 3, 5) is not a chunk.

Examples2

  1. Example 1

    Input
    5 2
    1 -2 3 -4 5
    
    Expected output
    6
    
  2. Example 2

    Input
    5 -2
    1 -2 3 -4 5
    
    Expected output
    13