1 条题解
-
0
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; int a[N]; long long s[N];//保险起见,开long long int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,S; cin>>n>>S; for(int i=1;i<=n;i++){ cin>>a[i]; s[i]=a[i]+s[i-1]; } int r=0,ans=n+1; if(s[n]<S)cout<<"0"; else{ for(int l=1;l<=n;l++){ while(r<=n&&s[r]-s[l-1]<S)r++; if(r>n)break;//r为r+1时跳出循环,因为区间和小于S且无法再增长 ans=min(ans,r-l+1); } cout<<ans; } return 0; }
- 1
信息
- ID
- 436
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 111
- 已通过
- 27
- 上传者