CF BUDDY
← Problems·

1994C · Hungry Games

1600 · binary search, dp, two pointers

Problem: Yaroslav is playing a computer game, and at one of the levels, he encountered nn mushrooms arranged in a row. Each mushroom has its own level of toxicity; the ii-th mushroom from the beginning has a toxicity level of aia_i. Yaroslav can choose two integers 1lrn1 \le l \le r \le n, and then his character will take turns from left to right to eat mushrooms from this subsegment one by one, i.e., the mushrooms with numbers l,l+1,l+2,,rl, l+1, l+2, \ldots, r.

The character has a toxicity level gg, initially equal to 00. The computer game is defined by the number xx — the maximum toxicity level at any given time. When eating a mushroom with toxicity level kk, the following happens:

  1. The toxicity level of the character is increased by kk.
  2. If gxg \leq x, the process continues; otherwise, gg becomes zero and the process continues.

Yaroslav became interested in how many ways there are to choose the values of ll and rr such that the final value of gg is not zero. Help Yaroslav find this number!

Input Format: Each test consists of multiple test cases. The first line contains an integer tt (1t1041 \le t \le 10^{4}) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains two integers nn, xx (1n2105,1x1091 \leq n \leq 2 \cdot 10^5, 1 \le x \le 10^9) — the number of mushrooms and the maximum toxicity level.

The second line of each test case contains nn numbers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \leq a_i \leq 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output Format: For each test case, output a single number — the number of subsegments such that the final value of gg will not be zero.

Note: In the first test case, the subsegments (1,1)(1, 1), (1,2)(1, 2), (1,4)(1, 4), (2,2)(2, 2), (2,3)(2, 3), (3,3)(3, 3), (3,4)(3, 4) and (4,4)(4, 4) are suitable.

In the second test case, non-zero gg will remain only on the subsegments (1,1)(1, 1) and (2,2)(2, 2).

In the third test case, on the only possible subsegment, gg will be zero.

Sample Cases

Case 1

Input

5
4 2
1 1 1 1
3 2
1 2 3
1 6
10
6 3
1 2 1 4 3 8
5 999999999
999999999 999999998 1000000000 1000000000 500000000

Output

8
2
0
10
7

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback