File size: 2,290 Bytes
07f695f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<p>
You've managed to become a contestant on the hottest new game show, The Price is Correct!
</p>

<p>
After asking you to come on down to the stage, the show's host presents you with a row of <strong>N</strong> closed boxes, 
numbered from 1 to <strong>N</strong> in order, each containing a secret positive integer. 
A curtain opens to reveal a shiny, new tricycle &mdash; you recognize it as an expensive, top-of-the-line model.
</p>

<p>
The host then proceeds to explain the rules: you must select a contiguous sequence of the boxes (boxes a..b, for some 1 &le; a &le; b &le; <strong>N</strong>). 
Your chosen boxes will then be opened, and if the sum of the numbers inside is no greater than the price of the tricycle, you win it!
</p>

<p>
You'd sure like to win that tricycle. Fortunately, not only are you aware that its price is exactly <strong>P</strong>, but you've paid off the host to let you in 
on the contents of the boxes! You know that each box <strong>i</strong> contains the number <strong>B<sub>i</sub></strong>.
</p>

<p>
How many different sequences of boxes can you choose such that you win the tricycle? Each sequence is defined by its starting and ending box indices (a and b).
</p>


<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of times you appear on The Price is Correct.
For each show, there is first a line containing the space-separated integers <strong>N</strong> and <strong>P</strong>. 
The next line contains <strong>N</strong> space-separated integers, <strong>B<sub>1</sub></strong> through <strong>B<sub>N</sub></strong> in order.
</p>


<h3>Output</h3>
<p>
For the <strong>i</strong>th show, print a line containing "Case #<strong>i</strong>: " followed by
the number of box sequences that will win you the tricycle.
</p>


<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 40 <br />
1 &le; <strong>N</strong> &le; 100,000 <br />
1 &le; <strong>P</strong> &le; 1,000,000,000 <br />
1 &le; <strong>B<sub>i</sub></strong> &le; 1,000,000,000 <br />
</p>


<h3>Explanation of Sample</h3>
<p>
In the first case no sequence adds up to more than 50, so all 10 sequences are winners. In the fourth case, you can select any single box, or the sequences (1, 2), (1, 3), and (2, 3), for 9 total winning sequences.
</p>