Sunny Needs Money

3.7

6 votes
Medium
Problem

Sunny is in trouble! He is out of money and has to wait few days before he can withdraw from his bank account, bank balance being R rupees. But he needs some money urgently. He’ll meet N friends on his way, ith friend can lend him Bi rupees. Help him choose friends to borrow money so that when he meets them it shall satisfy below conditions :

-Chosen friends meet him consecutively

-He borrows exactly Bi rupees from i'th friend

-Total borrowed money is ≤ R in else he won't be able to pay them back

In how many ways can he choose friends satisfying above constraints?

Input Format:

First integer T denotes number of times Sunny gets in this kind of situation. For each case there is a first line containing integers N and R.

The next line contains N space separated integers denoting amount of money ith friend can lend him, B1 to BN in order they meet Sunny

Output Format:

For each case, output number of ways he can choose his friends.

Constraints:

1 ≤ T ≤ 5

1 ≤ N ≤ 200000

1 ≤ R ≤ 4000000

1 ≤ Bi ≤ 4000000

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

In second case, he can choose friends to borrow from in following ways-

{1st}, {2nd}, {1st, 2nd}, {3rd}

i.e. {15}, {10}, {15, 10}, {30}

All combinations are contiguous and total borrowed money is ≤ 30.

Editor Image

?