4 条题解
-
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 200010; int a[N]; ll pre[N]; int n, S; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> S; for (int i = 1; i <= n; ++i) { cin >> a[i]; pre[i] = pre[i-1] + a[i]; } int l = 1, ans = 0; // 枚举右端点r,找最左的l使得 [l, r] 的和 ≤ S for (int r = 1; r <= n; ++r) { while (pre[r] - pre[l-1] > S) { l++; } ans = max(ans, r - l + 1); } cout << ans << endl; return 0; }
信息
- ID
- 820
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 715
- 已通过
- 160
- 上传者