fork download
  1. /*
  2. * @Author: hungeazy
  3. * @Date: 2026-03-04 23:24:15
  4. * @Last Modified by: hungeazy
  5. * @Last Modified time: 2026-04-02 23:00:33
  6. */
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. const int N = (int)1e6+10;
  10. int n,a[N],pre[N],k;
  11.  
  12. int main()
  13. {
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(NULL); cout.tie(NULL);
  16. cin >> n >> k;
  17. for (int i = 1; i <= n; i++) cin >> a[i];
  18. for (int i = 1; i <= n; i++) pre[i] = pre[i-1]+a[i];
  19. int ans = 0;
  20. for (int i = 1; i <= n; i++)
  21. {
  22. int l = i, r = n, pos = 0;
  23. while (l <= r)
  24. {
  25. int mid = (l+r)>>1;
  26. if (pre[mid]-pre[i-1] <= k) pos = mid, l = mid+1;
  27. else r = mid-1;
  28. }
  29. if (pos != 0) ans += pos-i+1;
  30. }
  31. cout << ans;
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty