POJ - 3061Subsequence(尺取法,模板)
题目描述
题目链接
A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a program to find the minimal length of the subsequence of consecutive elements of the sequence, the sum of which is greater than or equal to S.
Input
The first line is the number of test cases. For each test case the program has to read the numbers N and S, separated by an interval, from the first line. The numbers of the sequence are given in the second line of the test case, separated by intervals. The input will finish with the end of file.
Output
For each the case the program has to print the result on separate line of the output file.if no answer, print 0.
Sample Input
1 | 2 |
Sample Output
1 | 2 |
题解
尺取法模板题
- 求出前缀和
- 用两个指针来跑
需要注意的是, 如果sum[n] < k ,那就输出0, (因为这个wa了一发好难受
AC代码
1 |
|
1 | 恰似你一低头的温柔,娇弱水莲花不胜寒风的娇羞, 我的心为你悸动不休。 --mingfuyan |
原文作者: Mingfu Yan
原文链接: https://solodance.top/2020/06/26/POJ - 3061Subsequence(尺取法,模板)/
版权声明: 转载请注明出处(必须保留作者署名及链接)