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 题目大意: 求数组连续元素和大于等于K 的最小连续个数! 代码:
#include <iostream>

using namespace std;

int a[100005];

int main()
{
int T, n, K, pos, low, minn;
cin >> T ;
while(T--)
{
cin >> n >> K ;
minn = n ;
int sum = 0;
low = 0;
pos = 0;
for(int i=0; i<n; i++) cin >> a[i] ;
for( ; ; ++ low)
{
while(sum<=K && pos < n) sum += a[pos++] ;
if(sum<K) break ;
sum -= a[low];
minn = min(minn,pos-low);
}
if(minn==n) cout << "0" << endl ;
else cout << minn << endl ;
} return 0;
}

ACM题目————Subsequence的更多相关文章

  1. ACM题目————中缀表达式转后缀

    题目描述 我们熟悉的表达式如a+b.a+b*(c+d)等都属于中缀表达式.中缀表达式就是(对于双目运算符来说)操作符在两个操作数中间:num1 operand num2.同理,后缀表达式就是操作符在两 ...

  2. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

  3. ACM题目推荐(刘汝佳书上出现的一些题目)[非原创]

    原地址:http://blog.csdn.net/hncqp/article/details/1758337 推荐一些题目,希望对参与ICPC竞赛的同学有所帮助. POJ上一些题目在http://16 ...

  4. 有一种acm题目叫做,奇葩!

    本文全然没有技术含量,纯粹是娱乐. 我事实上想写点东西.可是近期好像做计算几何做得太多了,一种想说说不出东西的感觉,唯有写一下一些奇葩的题目了. HDU3337:Guess the number pi ...

  5. ACM题目————STL练习之求次数

    题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112 描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个 ...

  6. ACM题目————zoj问题

    题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:20322 解决:3560 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC. ...

  7. ACM题目————又见拦截导弹

    描述 大家对拦截导弹那个题目应该比较熟悉了,我再叙述一下题意:某国为了防御敌国的导弹袭击,新研制出来一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:它的第一发炮弹能够到达任意的高度,但是以后每一发炮 ...

  8. ACM题目————还是畅通工程

    Submit Status Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路 ...

  9. ACM题目————小A的计算器

    Description 以往的操作系统内部的数据表示都是二进制方式,小A新写了一个操作系统,系统内部的数据表示为26进制,其中0-25分别由a-z表示.  现在小A要在这个操作系统上实现一个计算器,这 ...

随机推荐

  1. Winform禁止容器内控件获得焦点时改变容器显示范围坐标

    在Winform中当容器的可视高度无法显示所有控件并且容器的AutoScroll属性设置为True的情况下,但点击容器内某个未显示完整的控件时,会出现容器的滚动条自动下滚的情况. 这是由于控件获得焦点 ...

  2. svn合并

    1.先去 aone里我的变更 里 重建 新分支 相当于重主干上拉代码下来2.然后再去 原来的分支里 swich切换到新分支3.在原来的分支里 merge 到新分支的url4.选择最早的 version ...

  3. MySQL: ERROR13(HY000):Can't get stat of

    在mysql中load data数据 mysql> load data infile '/home/a.txt' into table table_a;ERROR 13 (HY000): Can ...

  4. 体验Java的封装性

    package com.cnblogs.java; //体验Java的封装性 /* * 如下的人类年龄赋值-300岁,显然很不合理,这种直接对类的属性赋值,有时候虽然不合理但却会编译通过. * 所以我 ...

  5. windows 计算机 管理 命令

    compmgmt.msc

  6. [转]30分钟学会反向Ajax

    原文链接:http://www.cnblogs.com/learnhow/p/5708364.html 场景1:当有新邮件的时候,网页自动弹出提示信息而无需用户手动的刷新收件箱. 场景2:当用户的手机 ...

  7. html5新增全局属性

    data-* 如:data-type,data-role等 hidden  <div hidden></div> 隐藏该div spellcheck <textarea ...

  8. 深度学习 vs 机器学习 vs 模式识别

    http://www.csdn.net/article/2015-03-24/2824301 [编者按]本文来自CMU的博士,MIT的博士后,vision.ai的联合创始人Tomasz Malisie ...

  9. Axis2、Axis1 以及其他接口的调用方式

    在请求的时候出现问题,使用下面的方式请求就不会出现问题. package webservice.client.utils; import java.util.Iterator; import java ...

  10. ASP.NET MVC(二)

    休息一下还是继续ASP.NET MVC 的基础知识. 这篇文件我想和大家一起熟悉下ASP.NET MVC项目的目录结构及dll. 1. ASP.NET MVC 项目的目录结构 App_Data:  存 ...