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. c# 策略模式 加工厂模式-对象与行为分离

    计算器程序 策略模式是一种行为学模式.行为是同等级的算法  ,这些行为每个模式封装到一个类里 上端提供数据   ,下端提供算法 ,中间层context context  把上端的数据和算法  放到co ...

  2. Java开发MIS系统需要的技术及其作用

    1.后台框架部分,常用spring.struts2(Struts2框架,提供了一种基于MVC体系结构的工程序的开发方法,具有组件模块化.灵活性和重用性等优点,使基于MVC模式的程序结构更加清晰,同时也 ...

  3. 高负载PHP调优

    高负载PHP调优 针对PHP的Linux调优 调整文件描述符限制 # ulimit -n 1000000 # vi /etc/security/limits.conf # Setting Shell  ...

  4. sqlalchemy根据数据库结构生成映射的实体

    # !/usr/bin/python # -*- coding: UTF-8 -*- from sqlalchemy import * from sqlalchemy.orm import sessi ...

  5. Ajax(6) Ajax向servlet请求数据库操作 并显示到当前页面 这个未经测试

    假设:1.你的页面在Web-Root下,内容为: <div id="showMsg"></div><input type="text&quo ...

  6. 树状数组训练题2:SuperBrother打鼹鼠(vijos1512)

    先给题目链接:打鼹鼠 这道题怎么写? 很明显是树状数组. 而且,很明显是二维树状数组. 如果你没学过二维的树状数组,那么戳开这里:二维树状数组 看完以后,你就会知道怎么做了. 没有什么好解释的,几乎就 ...

  7. Scrapy框架爬虫

    一.sprapy爬虫框架 pip install pypiwin32 1) 创建爬虫框架 scrapy startproject Project # 创建爬虫项目 You can start your ...

  8. 682. Baseball Game

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  9. 2019.02.09 bzoj4710: [Jsoi2011]分特产(容斥原理)

    传送门 题意简述:有nnn个人,mmm种物品,给出每种物品的数量aia_iai​,问每个人至少分得一个物品的方案数(n,m,每种物品数≤1000n,m,每种物品数\le1000n,m,每种物品数≤10 ...

  10. String拼接

    1. String[] members=ArrayDATA_IDS; String usernames = ""; for(String id :members) { userna ...