POJ
来源:互联网 发布:淘宝能买到正规发票吗 编辑:程序博客网 时间:2024/06/06 05:25
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.
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.
For each the case the program has to print the result on separate line of the output file.if no answer, print 0.
210 155 1 3 5 10 7 4 9 2 85 111 2 3 4 5
23
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int a[100005];int main(){ int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); int i; for(i=1;i<=n;i++) { int x; scanf("%d",&x); a[i]=a[i-1]+x; } int ans=n+1; int j=1; i=1; for(j=1;j<=n;j++) { while(a[j]-a[i]>=m) { i++; ans=min(ans,j-i+1); //printf("%d\n",ans); } } if(ans==n+1) printf("0\n"); else printf("%d\n",ans); } return 0;}
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- cocos2dx打包到andoird机前的准备
- ubuntu14.04系统清理
- 类反射学习(二)JAVA开发框架底层思想演示,以及类反射的应用
- 实战docker,编写Dockerfile定制tomcat镜像,实现web应用在线部署
- Android中继承TextView实现文字的跑马灯效果
- POJ
- C++——NOIP模拟题——cheer
- openvSwtich学习(1)—— 源代码安装openvSwitch
- Spring AOP 实现功能权限校验功能
- P4 2017峰会前奏曲——P4培训会 | 北京站邀请函
- Cannot mix incompatible Qt library (version 0x40806) with this library (version 0x40807)
- tomcat和jdk安装配置
- SQL模式匹配
- oracle一个创建用户、创建表空间、授权、建表的完整过程和常用命令