Codeforces Round 510 (Div. 2)
D
Petya and Array
Codeforces
1800
原题
← CE →
翻译中…

Petya has an array $a$ consisting of $n$ integers. He has learned partial sums recently, and now he can calculate the sum of elements on any segment of the array really fast. The segment is a non-empty sequence of elements standing one next to another in the array.

翻译中…

Now he wonders what is the number of segments in his array with the sum less than $t$. Help Petya to calculate this number.

翻译中…

More formally, you are required to calculate the number of pairs $l, r$ ($l \le r$) such that $a_l + a_{l+1} + \dots + a_{r-1} + a_r \lt t$.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $t$ ($1 \le n \le 200\,000, |t| \le 2\cdot10^{14}$).

翻译中…

The second line contains a sequence of integers $a_1, a_2, \dots, a_n$ ($|a_{i}| \le 10^{9}$) — the description of Petya's array. Note that there might be negative, zero and positive elements.

翻译中…

Output

翻译中…

Print the number of segments in Petya's array with the sum of elements less than $t$.

翻译中…

Note

翻译中…

In the first example the following segments have sum less than $4$:

翻译中…
  • $[2, 2]$, sum of elements is $-1$
  • $[2, 3]$, sum of elements is $2$
  • $[3, 3]$, sum of elements is $3$
  • $[4, 5]$, sum of elements is $3$
  • $[5, 5]$, sum of elements is $-1$
翻译中…

样例

Input #1
5 4
5 -1 3 4 -1
Output #1
5
InputCopy OutputCopy
Input #2
3 0
-1 2 -3
Output #2
4
InputCopy OutputCopy
Input #3
4 -1
-2 1 -2 3
Output #3
3
InputCopy OutputCopy
题目信息
题号
1042D
时间限制
2 s
内存限制
256 MB
标签
数据结构
分治
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。