3 条题解
-
0
#include<bits/stdc++.h> using namespace std; const int N=2e5+5; int a[N]; long long s[N]; 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=0; for(int l=1;l<=n;l++){ if(ans>=n-l+1)break;//剪枝 while(r<=n&&s[r]-s[l-1]<=S)r++; ans=max(ans,r-l); if(r>n)break; } cout<<ans; return 0; } -
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll T=1;const ll N=2e5+5; ll n,x,y; ll pre[N];ll a[N];ll ans=0; void solve(){ cin>>n>>x; for(ll i=1;i<=n;++i){ cin>>a[i];pre[i]=pre[i-1]+a[i]; } ll l=1;ll r=1; while(r<=n){ if(pre[r]-pre[l-1]<=x){ ans=max(ans,r-l+1);r++; } else l++; }cout<<ans; } int main(){ while(T--)solve(); return 0; } ```echarts
- 1
信息
- ID
- 820
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 664
- 已通过
- 150
- 上传者