求字段和问题
Petr is a Bachelor of Mathematics. He is about to graduate, and need to finish a graduation design. His design is about sum of an array. He is given an array of positive numbers, and a number M. He is asked to find out how many sub-array have a sum that is less than M.
Input
There are several cases in the input. For each case, first given a number n, which tells how many numbers are there in the array, and a M, followed by n numbers.
n will be positive and no larger than 20000,while M less than 400000000,your given numbers in the array will be no larger than 20000. n=0 and M=0 terminates the input.
Output
Output the answer for each case, one in a line.
Sample Input
5 7
1 1 4 5 2
2 100
10 9
0 0
Sample Output
8
3
请问有什么比较好的算法不,要求其复杂度低于O(n^2),不然超时了,不使用2层遍历