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

2
10 15
5 1 3 5 10 7 4 9 2 8
11
1 2 3 4 5

Sample Output

2
3
题解:求连续子序列和大于等于s的最小长度。可以尺取,若sum<s,左指针右移,若sum>=s右指针左移,当sum<s时左指针继续右移,满足条件打擂台即可。
 #include<cstring>
#include<cstdio>
#include<algorithm>
#define Inf 0x3f3f3f3f
#define ll long long
using namespace std;
ll str[];
int main()
{
ll i,j,m,n,t;
scanf("%lld",&t);
while(t--)
{
scanf("%lld%lld",&m,&n);
for(i=;i<m;i++)
{
scanf("%lld",&str[i]);
}
ll sum=,cnt=,cur=,flag=,ans=Inf,count1=;
while(cur<m)
{
while(count1<m&&sum<=n)
{
sum+=str[count1++];
}
if(sum<n)
break;
flag=;
sum-=str[cur];
ans=min(ans,count1-cur);
cur++;
}
if(flag)
printf("%lld\n",ans);
else
puts("");
}
return ; }

Sequence(尺取)的更多相关文章

  1. NOJ 1072 The longest same color grid(尺取)

    Problem 1072: The longest same color grid Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit in ...

  2. poj2566尺取变形

    Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...

  3. poj2100还是尺取

    King George has recently decided that he would like to have a new design for the royal graveyard. Th ...

  4. POJ 2566 Bound Found 尺取 难度:1

    Bound Found Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 1651   Accepted: 544   Spec ...

  5. poj3061 Subsequence(尺取)

    Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...

  6. POJ3061 Subsequence 尺取or二分

    Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...

  7. Sum of Consecutive Prime Numbers(素数打表+尺取)

    Description Some positive integers can be represented by a sum of one or more consecutive prime numb ...

  8. Bound Found(思维+尺取)

    Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...

  9. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】

    任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...

随机推荐

  1. java String 转 Long 两种方法区别

    Long.ValueOf("String")返回Long包装类型 包装类型: Byte,Integer,Short,Long,Boolean,Character,Float,Dou ...

  2. InpOutx64 替代 winIOx64

    /***************************************************************************** * InpOutx64 替代 winIOx ...

  3. Android 拍照或从相册取图片并裁剪

    在Android中,Intent触发Camera程序,拍好照片后,将会返回数据,但是考虑到内存问题,Camera不会将全尺寸的图像返回给调用的Activity,一般情况下,有可能返回的是缩略图,比如1 ...

  4. Consul做服务发现

    使用Consul做服务发现的若干姿势 https://www.cnblogs.com/bossma/p/9756809.html 从2016年起就开始接触Consul,使用的主要目的就是做服务发现,后 ...

  5. 数据库连接配置 app.config web.config

    通过ADO.Net连接程序和SQLServer数据库的连接字符串: connectionString ="server=(local);database=Demo;integrated se ...

  6. 序列化 SqlAlchemy 的结果为 json 字符串

    http://my.oschina.net/gongshang/blog/395431?p=1 在设计 RESTful 的网站时,我们总是希望 ORM 框架返回的结果是可以直接给 View 层使用的 ...

  7. STM32F103外部晶振由8M变为12M

    STM32官方提供的库文件中,HSE(外部高速时钟)默认为8MHz,最高主频为8*9=72MHz,如果将HSE变为12MHz,不修改库文件的话,最高主频则变为12*9=108MHz,最典型的问题就是U ...

  8. the road of test

    1.firefox打印兼容问题: <HTML> <HEAD> <TITLE>JavaScript利用IE内置打印控件IEWebBrowser进行打印/打印页面设置/ ...

  9. Linux常用命令(个人使用频率较高)

    1,日志查看 tail(cat) -f|grep ERROR(任意字符) filepath (任意行数) -f|grep ERROR(任意字符) filepath 2,查看目录&授权 file ...

  10. 1、python基础速成

    基础模块 def prt(age,name):#函数定义 print("%s is %d 年龄 old"%(name,age)) if __name__=="__main ...