subsequence
tl:1s, ML:32MB
Description
A sequence of n positive integers (< n <), each of the them less than or equal 10000, and a positive integer S (S <) 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. The program have to read the numbers N and S, separated by a interval, from the first line. The numbers of the sequence is given in the second line of the "test case", separated by intervals. The input would finish with the end of file.
Output
The the program have to print the result on separate line of the output File.if no answer, print 0.
Sample Input
210 155 1 3 5 10 7 4 9 2 85 111 2 3 4 5
Sample Output
23
Source
Southeastern Europe 2006
Exercises
The use of the second bomb, casual can be a series
1#include <stdio.h>2 using namespacestd;3 inttestc,n,s,a[100010],RR;4 intMain () {5scanf"%d",&TESTC);6 while(testc--) {7scanf"%d%d", &n,&s); rr=n+1;8 for(intI=0; i<n;++i) scanf ("%d",&a[i]);9 ints=0, t=0, ns=0;Ten for (;;) { One while(t<n&&ns<s) ns+=a[t++]; A if(Ns<s) Break; - if(T-S<RR) rr=t-s; -ns-=a[s++]; the } - if(rr>n) rr=0; -printf"%d\n", RR); - } +}View Code
[POJ 3061] Subsequence