1 条题解
-
0
C++ :
#include<iostream> #include<cstdio> using namespace std; int n,m; int s,e; int tot=0; int ans=0; int h[250000]={0}; char ch; int ret; int qin() { ret=0; while(ch=getchar(),!isdigit(ch)); while(ret=ret*10+ch-'0',ch=getchar(),isdigit(ch)); return ret; } void work() { s=1; e=0; tot=0; ans=0; for(int i=1;i<=n;++i) { e++; h[i]=qin(); tot+=h[i]; while(tot>=m) { if(ans==0||e-s+1<ans) { ans=e-s+1; } tot-=h[s]; s++; } } printf("%d",ans); } int main() { scanf("%d%d",&n,&m); work(); while(scanf("%d%d",&n,&m)!=EOF) { printf("\n"); work(); } return 0; }
- 1
信息
- ID
- 2160
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者