CF2086B.Large Array and Segments

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Large Array and Segments

There is an array aa consisting of nn positive integers, and a positive integer kk. An array bb is created from array aa according to the following rules:

  • bb contains nkn \cdot k numbers;
  • the first nn numbers of array bb are the same as the numbers of array aa, that is, bi=aib_{i} = a_{i} for ini \le n;
  • for any i>ni \gt n, it holds that bi=binb_{i} = b_{i - n}.

For example, if a=[2,3,1,4]a = [2, 3, 1, 4] and k=3k = 3, then b=[2,3,1,4,2,3,1,4,2,3,1,4]b = [2, 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4].

Given a number xx, it is required to count the number of such positions ll (1lnk1 \le l \le n \cdot k), for which there exists a position rlr \ge l, such that the sum of the elements of array bb on the segment [l,r][l, r] is at least xx (in other words, bl+bl+1++brxb_{l} + b_{l+1} + \dots + b_{r} \ge x).

Input

Each test consists of several test cases. The first line contains one integer tt (1t1041 \le t \le 10^{4}) — the number of test cases. The description of the test cases follows.

The first line of each test case contains three integers nn, kk, xx (1n,k1051 \le n, k \le 10^{5}; 1x10181 \le x \le 10^{18}).

The second line of each test case contains nn integers aia_{i} (1ai1081 \le a_{i} \le 10^{8}).

Additional constraints on the input:

  • the sum of nn across all test cases does not exceed 21052 \cdot 10^{5};
  • the sum of kk across all test cases does not exceed 21052 \cdot 10^{5}.

Output

For each test case, output one integer — the number of suitable positions ll in the array bb.

Note

In the first test case, the array bb looks like this:

$$[3, 4, 2, 1, 5, 3, 4, 2, 1, 5, 3, 4, 2, 1, 5]$$</p><p>There are$12$positions$l$for which there exists a suitable position$r$. Here are some (not all) of them:</p><ul> <li>$l = 1$, for which there is a position$r = 6$, the sum over the segment$[1, 6]$equals$18$; </li><li>$l = 2$, for which there is a position$r = 5$, the sum over the segment$[2, 5]$equals$12$; </li><li>$l = 6$, for which there is a position$r = 9$, the sum over the segment$[6, 9]$equals$10$. ## Samples ```input1 7 5 3 10 3 4 2 1 5 15 97623 1300111 105 95 108 111 118 101 95 118 97 108 111 114 97 110 116 1 100000 1234567891011 1 1 1 1 1 1 1 1 2 2 1 2 1 1 2 1 5 2 1 ``` ```output1 12 1452188 0 1 1 1 0 ```$$

在线编程 IDE

建议全屏模式获得最佳体验