1 条题解
-
1
AC代码,放心食用
#include <iostream> using namespace std; int t, n, s, p = 1, q = 1a[200005], sum[200005]; int main() { cin >> t; while (t--) { cin >> n >> s; for (int i = 1; i <= n; i++) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; } if (sum[n] < s) { cout << -1; continue; } while (q < =n && sum[q] <= s) q++; int ans = n - (q - 1); while (q <= n) { while (p <= n && a[p - 1] != 1) p++; while (q <= n && sum[q] - sum[p - 1] <= s) q++; ans = min(ans, p - 1 + (n - q + 1)); p++; } cout << ans << endl; } return 0; }
- 1
信息
- ID
- 1936
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- (无)
- 递交数
- 497
- 已通过
- 26
- 上传者