Description

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
5 11
1 2 3 4 5

Sample Output

2
3

Source

Southeastern Europe 2006
 
 
题目大意:

尺取。练练手。
program rrr(input,output);
var
a:array[..]of longint;
t,n,s,i,j,k,sum,ans:longint;
function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;
begin
assign(input,'r.in');assign(output,'r.out');reset(input);rewrite(output);
readln(t);
for k:= to t do
begin
readln(n,s);
for i:= to n do read(a[i]);
j:=;sum:=;ans:=n+;
for i:= to n do
begin
while (j<n) and (sum<s) do begin inc(j);sum:=sum+a[j]; end;
if sum<s then break;
ans:=min(ans,j-i+);
sum:=sum-a[i];
end;
if ans>n then writeln() else writeln(ans);
end;
close(input);close(output);
end.

poj3061 Subsequence(尺取)的更多相关文章

  1. POJ3061 Subsequence 尺取or二分

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

  2. POJ 3061 Subsequence 尺取

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14698   Accepted: 6205 Desc ...

  3. POJ3061——Subsequence(尺取法)

    Subsequence POJ - 3061 给定长度为n的数列整数a0,a1,a2-an-1以及整数S.求出总和不小于S的连续子序列的长度的最小值,如果解不存在输出0. 反复推进区间的开头和末尾,来 ...

  4. POJ-3061 Subsequence 二分或尺取

    题面 题意:给你一个长度为n(n<100000)的数组,让你找到一个最短的连续子序列,使得子序列的和>=m  (m<1e9) 题解: 1 显然我们我们可以二分答案,然后利用前缀和判断 ...

  5. poj3061 Subsequence(尺取法)

    https://vjudge.net/problem/POJ-3061 尺取发,s和t不断推进的算法.因为每一轮s都推进1所以复杂度为O(n) #include<iostream> #in ...

  6. Subsequence (POJ - 3061)(尺取思想)

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

  7. 【单调队列+尺取】HDU 3530 Subsequence

    acm.hdu.edu.cn/showproblem.php?pid=3530 [题意] 给定一个长度为n的序列,问这个序列满足最大值和最小值的差在[m,k]的范围内的最长子区间是多长? [思路] 对 ...

  8. poj2566尺取变形

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

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

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

随机推荐

  1. form提交方式Get与Post详解

    form作为Html的一个元素,它就是为了客户端提交数据而产生的,它有两个很重要的属性action和method,action属性指明了处理提交的数据的应用程序的URL,而method有两个值:POS ...

  2. 【敏捷】7.showcase,开发中必须引起重视的小环节

    有人说,测试者来自火星,开发者来自金星.这是因为软件测试员和软件开发者就好比一对冤家,里面的缘由说不清也道不明.开发代表着创造,而测试则代表着摧毁,因为测试的目的就是以各种方式不断地从开发出的产品中发 ...

  3. PLSQL_数据泵Datapump导入导出数据IMPDP / EXPDP(概念)(Oracle数据导入导出工具)(转)

    一.摘要 在平常备库和数据库迁移的时候,当遇到大的数据库的时候在用exp的时候往往是需要好几个小时,耗费大量时间.oracle10g以后可以用expdp来导出数据库花费的时间要远小于exp花费的时间, ...

  4. mysql 分页查询时,如何正确的获取总数

    1. 普遍方法: 使用 COUNT(*) ,例如: SELECT COUNT(*) as total FROM studentTask WHERE subjectName = '高中数学'; 缺点: ...

  5. hdu2795 Billboard(线段树单点修改)

    传送门 结点中的l和r表示层数,maxx表示这层最多还剩下多少宽度.根据公告的宽度取找到可以放的那一层 找到后返回层数,并修改maxx #include<bits/stdc++.h> us ...

  6. dubbo 多人开发时(即开发环境),版本号不要一致

    导致问题:如果版本号相同,会调到别人的服务 不需要修改配置文件.直接改idea配置即可. Configurations ====> 添加parameters ===> dubbo.cons ...

  7. Linux速成(二)

    四.Linux 系统目录结构 树状目录结构: 以下是对这些目录的解释: /bin:bin是Binary的缩写, 这个目录存放着最经常使用的命令. /boot:这里存放的是启动Linux时使用的一些核心 ...

  8. c++面向对象程序设计总结(类的使用)

    本篇算是学习c++有关类的知识的一些易错点吧..... 并不是特别详细,以后会更新吧.... 几点并不关于类的东西 1.函数模板,用虚拟类型来实现模板的功能 #include<iostream& ...

  9. docker pull下来的镜像放哪儿了?

    本机docker版本 docker –version Docker version 1.进入docker 目录 root@Rightsec:~# cd /var/lib/docker root@Rig ...

  10. Linux上安装设置mysql 5.7.24

    一,准备 1,先查看Linux是32位还是64位 getconf LONG_BIT 如果返回的是32,那么就是32位 如果返回的是64,那么就是64位 2,如果服务器不能联网,就先去官网下载好压缩包, ...