博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Subsequence(二分)
阅读量:5374 次
发布时间:2019-06-15

本文共 1473 字,大约阅读时间需要 4 分钟。

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

210 155 1 3 5 10 7 4 9 2 85 111 2 3 4 5

Sample Output

23

一开始c++交不过,g++过,原来是int 输入的时候是long long,wa了,g++交没这个问题

代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
const int maxn=1e5+5;typedef long long ll;using namespace std;ll a[maxn];ll s[maxn];ll n,ss;bool check(int x){ if(x>=n) { return true; } for(int t=x;t<=n;t++) {// cout<
<<" "<
<
=ss) { return true; } } return false;}int main(){ int T; cin>>T; while(T--) { scanf("%lld%lld",&n,&ss); for(int t=1;t<=n;t++) { scanf("%lld",&a[t]); } memset(s,0,sizeof(s)); for(int t=1;t<=n;t++) { s[t]=s[t-1]+a[t]; } if(s[n]

 

转载于:https://www.cnblogs.com/Staceyacm/p/10781772.html

你可能感兴趣的文章
uva 12097 - Pie(二分,4级)
查看>>
mongodb索引
查看>>
nginx源码学习资源(不断更新)
查看>>
【bzoj2882】工艺 后缀自动机+STL-map
查看>>
[redis] redis
查看>>
Linux的加密认证功能以及openssl详解
查看>>
[Tools] 使用XP远程登录Win8系统
查看>>
【RL-TCPnet网络教程】第38章 TFTP简单文件传输基础知识
查看>>
HDU- 2265 Encoding The Diary
查看>>
socket基本概念
查看>>
在Windows上使用putty连接一台Linux主机
查看>>
Socket常见错误
查看>>
百度地图2.0API和3.0API。你想要的百度地图的这都有
查看>>
专业词汇
查看>>
星期五的收获
查看>>
proxmox 去除订阅提示
查看>>
使用Html.EditorFor()为文本框加上maxlength,placeholder等属性
查看>>
[转]后缀数组求最长重复子串
查看>>
设计模式——外观模式详解
查看>>
mysql (一)
查看>>