Subsequence
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 14709   Accepted: 6210

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


—————————————————————————————————————
题目的意思是给出n个整数,求区间和大于等于m的最小区间长度
思路:由于和具有单调性,直接尺取法
#include <iostream>
#include <functional>
#include <stdio.h>
#include <queue>
#include<cmath>
#include<algorithm>
using namespace std;
#define LL long long
const int inf=0x3f3f3f3f;
int n,m;
int a[1000005];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int l=0,r=0;
int sum=0;
int ans=inf;
while(1)
{
while(r<n&&sum<m)
{
sum+=a[r++];
}
if(sum<m) break;
ans=min(ans,r-l);
sum-=a[l++];
}
if(ans==inf)
ans=0;
printf("%d\n",ans);
}
return 0;
}


POJ2061 Subsequence 2017-05-25 19:49 83人阅读 评论(0) 收藏的更多相关文章

  1. 利用Python分析GP服务运行结果的输出路径 & 实现服务输出路径的本地化 分类: Python ArcGIS for desktop ArcGIS for server 2015-08-06 19:49 3人阅读 评论(0) 收藏

    最近,一直纠结一个问题:做好的GP模型或者脚本在本地运行,一切正常:发布为GP服务以后时而可以运行成功,而更多的是运行失败,甚至不能知晓运行成功后的结果输出在哪里. 铺天盖地的文档告诉我,如下信息: ...

  2. HDU1233 还是畅通工程 2017-04-12 19:49 64人阅读 评论(0) 收藏

    还是畅通工程 Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  3. 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏

    制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...

  4. HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏

    Happy Necklace                                                                           Time Limit: ...

  5. Basic 分类: POJ 2015-08-03 15:49 3人阅读 评论(0) 收藏

    Basic Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 905 Accepted: 228 Description The p ...

  6. 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...

  7. one recursive approach for 3, hdu 1016 (with an improved version) , permutations, N-Queens puzzle 分类: hdoj 2015-07-19 16:49 86人阅读 评论(0) 收藏

    one recursive approach to solve hdu 1016, list all permutations, solve N-Queens puzzle. reference: t ...

  8. Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏

    Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...

  9. IP Address 分类: POJ 2015-06-12 19:34 12人阅读 评论(0) 收藏

    IP Address Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 19125   Accepted: 11053 Desc ...

随机推荐

  1. js数据类型和变量

    Number JavaScript不区分整数和浮点数,统一用Number表示: 123 0.345 -99 NaN 当无法计算结果时用NaN表示 Infinity 表示无限大,当数值超过js的Numb ...

  2. Android.HowToDefineCustomView

    Custom View Errors E1 在使用自定义CustomView时,出现以下runtime error: Android.View.InflateException: Binary XML ...

  3. PS制作纸质复古野外露营插画分享

    经常有人说一些复古风,就觉得蛮难,其实制作过程其实没有想象中复杂,从1850年到2017年,通过这160多年里的平面设计,给我们的作品添加上一些新鲜的灵感和活力,本次教程就来教大家用PS做出耐看的纸质 ...

  4. Servlet会话管理二(Cookie)

    Cookie是在HTTP协议下,将服务器传递给浏览器的的少量信息保存到浏览器客户端的一种技术,通过这种技术,即使在浏览器被关闭或链接中断的情况下,用户仍可以维护Cookie中的数据. Cookie是经 ...

  5. 增加samba用户提示Failed to add entry for user

    1.首先在Ubuntu安装好samba,具体步骤为:安装samba:sudo apt-get install samba安装smbclient:sudo apt-get install 安装smbfs ...

  6. Ubuntu 双网卡设置

    闲话不多说,直接正题 因为chinanet信号不强,所以买了个usb无线网卡,平常又要做开发,要连着开发板,不知怎么回事,一旦自带无线网卡连上内网的无线路由,就不能访问外网了. 网上搜了好久,终于查到 ...

  7. struts2升级

    http://www.blogjava.net/ldwblog/archive/2013/10/14/404944.html

  8. window下文件在Linux下文件乱码解决

    在使用iconv转换文件的字符编码时,如果遇到类似“iconv: illegal input sequence at position”的错误,原因是需要转换的字符编码没有涵盖文件中的字符,比如,将一 ...

  9. jvm 启动参数设置(转载)

    JVM启动参数 http://onlyor.iteye.com/blog/1722413 博客分类: java java java启动参数共分为三类其一是标准参数(-),所有的JVM实现都必须实现这些 ...

  10. Django之admin管理数据库,cookie验证及分页设置

    一.admin管理数据库 1)models.py创建class类表 class Book(models.Model): name=models.CharField(max_length=) price ...